var deg = rad * Mathf.Rad2Deg
var rad = deg * Mathf.Deg2Rad
Minimalism in Programming: how to Minimize Risk and Maximize Success https://t.co/KSVq4ReI8m
— Maxime Chevalier (@Love2Code) 18 février 2018
Great read. Same here, code is a highly malleable way to express needs/solve problems. red flags:
— Sven Bergström (@___discovery) 18 février 2018
- no problems to solve for the goal
- solving wrong problems
- solving problems you don't have
- solving future theoretical problems
answer unknowns by exploring through iteration https://t.co/vkw40NVN8d
// Fonction
public static T rand<T>(T a, T b) {
return Random.value > 0.5f ? a : b;
}
int entier = rand ( 10 , 22 );
double dbl = rand ( 3.14 , 1.618 );
string str = rand ( "3.14" , "42" );
// Struct
public struct Tuple<T,U> {
public T left;
public U right;
}
// Class
public class ListOfTuple<T,U> {
public List<Tuple<T,U>> collection = new List<Tuple<T,U>>();
}
private ScriptName scripteRef;
// Use this for initialization
void Start () {
// Récupère une référence au script ScriptName attaché au même GameObject
scripteRef = GetComponent ();
}
public Transform otherGameObjectTransform;
public GameObject otherGameObject2;
private ScriptName scripteRef;
private ScriptName scripteRef2;
void Start () {
// scripteRef attaché à otherGameObjectTransform
scripteRef = otherGameObjectTransform.gameObject.GetComponent ();
Transform parent = otherGameObjectTransform.parent;
// scripteRef2 attaché à otherGameObject2
scripteRef2 = otherGameObject2.GetComponent ();
GameObject parent2 = otherGameObject2.transform.parent.gameObject;
}
// Use this for initialization
void Start () {
IEnumerable<Transform> children = (IEnumerable<Transform>) this.transform;
foreach (Transform child in children) {
child.gameObject.GetComponent<ScriptName>(); // peut être null !
}
foreach (Transform child in this.transform) {
child.gameObject.GetComponent<ScriptName>(); // peut être null !
}
foreach (ScriptName script in this.GetComponentsInChildren<ScriptName>()) {
// script n'est pas null
}
}
StartCoroutine (DoShake ());
IEnumerator DoShake () {
Quaternion originalRotation = this.transform.rotation;
int durationInFrames = 20;
for (int i = 0; i < durationInFrames; i++) {
this.transform.rotation = Quaternion.Euler (0, 0, 360f / durationInFrames);
yield return null; // wait next frame before continuing
}
this.transform.rotation = originalRotation;
}
EventManager.TriggerEvent("Shake");
EventManager.StartListening ("Shake", this.OnShake);
EventManager.StopListening ("Shake", this.OnShake);
Random.InitState(1);
Debug.Log(Random.Range(-10, 10)); // always 4
Debug.Log(Random.value); // always 0.7742628
Debug.Log(Random.ColorHSV()); // always RGBA(0.344, 0.321, 0.594, 1.000)
Debug.Log(Random.rotation.eulerAngles.z); // always 253.6533
Random.InitState(1);
Debug.Log(Random.Range(-10, 10)); // always 4
Debug.Log(Random.value); // always 0.7742628
Debug.Log(Random.ColorHSV()); // always RGBA(0.344, 0.321, 0.594, 1.000)
Debug.Log(Random.rotation.eulerAngles.z); // always 253.6533
Random.InitState(2);
Debug.Log(Random.Range(-10, 10)); // always -4
Debug.Log(Random.value); // always 0.0996678
Debug.Log(Random.ColorHSV()); // always RGBA(0.329, 0.235, 0.319, 1.000)
Debug.Log(Random.rotation.eulerAngles.z); // always 206.4019
Random.InitState(System.Environment.TickCount); // unpredictable