World space Canvas: https://docs.unity3d.com/Manual/HOWTO-UIWorldSpace.html
Vector3 scale = meters / canvas_width * Vector3.zero
World space Canvas: https://docs.unity3d.com/Manual/HOWTO-UIWorldSpace.html
Vector3 scale = meters / canvas_width * Vector3.zero
#Scaling Unity UI World space Canvas formulae -> Scale = unit in meters / canvas_width
Using index
for(int i=0;i<starManager.transform.childCount; i++)
{
Transform child = starManager.transform.GetChild(i);
}
Using Enumerator
foreach(Transform child in starManager.transform)
{
}
Editor Script remove all children (LINQ)
List<Transform> tempList = t.transform.Cast<Transform>().ToList();
tempList.ForEach(x => DestroyImmediate(x.gameObject));
using UnityEngine;
using System.Collections;
public class Monster : MonoBehaviour {
public enum State {
Crawl,
Walk,
Die,
}
public State state;
IEnumerator CrawlState () {
Debug.Log("Crawl: Enter");
while (state == State.Crawl) {
yield return 0;
}
Debug.Log("Crawl: Exit");
NextState();
}
IEnumerator WalkState () {
Debug.Log("Walk: Enter");
while (state == State.Walk) {
yield return 0;
}
Debug.Log("Walk: Exit");
NextState();
}
IEnumerator DieState () {
Debug.Log("Die: Enter");
while (state == State.Die) {
yield return 0;
}
Debug.Log("Die: Exit");
}
void Start () {
NextState();
}
void NextState () {
string methodName = state.ToString() + "State";
System.Reflection.MethodInfo info =
GetType().GetMethod(methodName,
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
StartCoroutine((IEnumerator)info.Invoke(this, null));
}
}
private float GetPercentageAlong(Vector3 a, Vector3 b, Vector3 c)
{
var ab = b - a;
var ac = c - a;
return Vector3.Dot(ac, ab) / ab.sqrMagnitude;
}
IF Type.GetType() throws null reference error (Unity bug) on build:
Assembly.Load("Assembly-CSharp").GetType(node.Name);
using System;
namespace StateMachine
{
public class Machine<T> where T : struct, IConvertible
{
protected T _currentState;
public Machine()
{
if (!typeof(T).IsEnum)
{
throw new ArgumentException("T must be an enumeration");
}
}
public virtual T InOut(T input)
{
_currentState = input;
return input;
}
}
}
Usage:
public enum EnemyState
{
Idle,
Sleeping,
Patrolling
}
public class EnemyMachine : Machine<EnemyState>
{
//Your logic here
}
EnemyMachine eMachine = new EnemyMachine;