Unity UI: Click Me? Click You!
To prevent UI clicks from filtering down to other objects: using UnityEngine.EventSystems; if (EventSystem.current.IsPointerOverGameObject ()) return; // Check if on a UI Object, if so ignore
To prevent UI clicks from filtering down to other objects: using UnityEngine.EventSystems; if (EventSystem.current.IsPointerOverGameObject ()) return; // Check if on a UI Object, if so ignore
To change an object’s texture ‘runtime’ via code: public Texture theTexture; gameObject.GetComponent<Renderer> ().material.SetTexture (“_MainTex”, theTexture);
void Whatever() { float delay = 1.0f; StartCoroutine(DoSomethingAfterWaiting(delay)); } IEnumerator DoSomethingAfterWaiting(float delay) { yield return new WaitForSeconds(delay); // Add Code here to Do it, Do it, Do it till you’re satisfied… whatever it is yield break; }
public AudioClip[] sndName; AudioSource sound = GetComponent<AudioSource>(); int sndDx = 0; float volume = .5; sound.PlayOneShot(sndName[sndDx], volume);
To ‘disable’ a Unity Button and show its disabled color, DO NOT DISABLE the button, simply set buttonName.interactable = false;
Turn an object’s display on or off: object.GetComponent <MeshRenderer>().enabled = true or false Turn Child object’s display on or off: foreach (Transform child in object.transform) { child.gameObject.GetComponent <MeshRenderer>().enabled = true or false; }
Create: List <type> name = new List <type>(); Add: name.Add( type/value ); Clear: name.Clear(); Number of Elements: name.Count;