Herramientas de usuario

Herramientas del sitio


fw:unity3d:environtment2d

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
fw:unity3d:environtment2d [2014/04/08 13:21]
alfred [How to do...]
fw:unity3d:environtment2d [2020/05/09 09:25] (actual)
Línea 18: Línea 18:
 === Inherited functions === === Inherited functions ===
   * Lifetime functions:   * Lifetime functions:
-    * ''​Awake()'',​ it's called while the script is loaded. Used to initialize instances.+    * ''​Awake()'',​ it's called while the script is loaded. Used to initialize instances. At this point it can not interact with other GameObjects.
     * ''​Start()'',​ it's called after Awake(). The difference is that this method won't be called if the script is not enabled.     * ''​Start()'',​ it's called after Awake(). The difference is that this method won't be called if the script is not enabled.
     * ''​Update()'',​ update funcition, one by frame.     * ''​Update()'',​ update funcition, one by frame.
Línea 26: Línea 26:
   * ''​OnDisable()''​   * ''​OnDisable()''​
   * ''​OnGUI()''​   * ''​OnGUI()''​
 +
 +Properties
 +  * ''​transform'',​ contains the methods and objects to move the object.
  
 === Interact with objects === === Interact with objects ===
Línea 32: Línea 35:
   * ''​Invoke(name,​ time)''​   * ''​Invoke(name,​ time)''​
   * ''​GameObject.Find(name)''​   * ''​GameObject.Find(name)''​
-  * ''​gameObject.GetComponent<​typeOfComponent>​()''​ gets the first component (script, whatever...) from a GameObject object. There is also ''​GetComponents<​type>​()''​ that retrieves a list. +  * ''​gameObject.GetComponent<​typeOfComponent>​()''​ gets the first component (script, whatever...) from a GameObject object. There is also ''​GetComponents<​type>​()''​ that retrieves a list.  The GameObject must be active.
   * ''​GetComponentInChildren<​Type>​()'',​ retrieves from children object.   * ''​GetComponentInChildren<​Type>​()'',​ retrieves from children object.
   * ''​Destroy(gameObject,​ time)'',​ will destroy an instatiated prefab on 20secs.   * ''​Destroy(gameObject,​ time)'',​ will destroy an instatiated prefab on 20secs.
   * ''​Destroy(gameObject)'',​ destroys the object now.   * ''​Destroy(gameObject)'',​ destroys the object now.
 +  * ''​SendMessage'',​ calls a method on each script which have it inside the GameObject.
 +<code csharp>
 +// Calls the function ApplyDamage with a value of 5
 +gameObject.SendMessage ("​ApplyDamage",​ 5.0);
 +...
 +// Every script attached to the game object ​
 +// that has an ApplyDamage function will be called.
 +function ApplyDamage (damage : float) {...
 +</​code>​
  
   * Propiedades:​   * Propiedades:​
Línea 69: Línea 81:
   * ''​Debug.Log()'',​ shows a message in console.   * ''​Debug.Log()'',​ shows a message in console.
   * ''​Debug.Break()'',​ stops the game.   * ''​Debug.Break()'',​ stops the game.
 +
 +=== Camera ===
 +The static object ''​Camera.main''​ contains the main camera for the scene.
 +  * ''​ViewportToWorldPoint''​ and ''​WorldToViewportPoint''​ to transform coordinates.
  
 === Useful functions === === Useful functions ===
Línea 163: Línea 179:
 <code csharp> <code csharp>
 GetComponent(MeshRenderer).enabled = false; GetComponent(MeshRenderer).enabled = false;
 +</​code>​
 +
 +=== Make blink a gameObject ===
 +For a finite amount of time...
 +<code csharp>
 +StartCoroutine(Blink(2.0)); ​
 +function Blink(waitTime : float) {
 +    var endTime=Time.time + waitTime;
 +    while(Time.time<​waitTime){
 +        renderer.enabled = false;
 +        yield WaitForSeconds(0.2);​
 +        renderer.enabled = true;
 +        yield WaitForSeconds(0.2);​
 +    }
 +}
 +</​code>​
 +To make it blink always, immiately, and repeat every 0.4 seconds...
 +<code csharp>
 +InvokeRepeating("​Blink",​ 0, 0.4);
 +function Blink()
 +{
 +    renderer.enabled = false;
 +    yield WaitForSeconds(0.2);​
 +    renderer.enabled = true;
 +}
 </​code>​ </​code>​
 ==== Notes ==== ==== Notes ====
Línea 239: Línea 280:
   * ''​Input.touchCount''​ tells the number of touches.   * ''​Input.touchCount''​ tells the number of touches.
   * ''​Input.GetTouch(0)''​ obtains the first touch which was done.   * ''​Input.GetTouch(0)''​ obtains the first touch which was done.
 +  * Sometimes you'll need to refresh the editor to see the changes, you can do it with ''​CTRL+R''​.
 +  * To focus a gameobject you'll do in the GameObject menu, option Align View to Selected.
  
 ==== GUI elements ==== ==== GUI elements ====
Línea 246: Línea 289:
 <code csharp> <code csharp>
 if (GUI.Button()) { if (GUI.Button()) {
 +</​code>​
 +To make a property which won't be shown in the editor:
 +<code csharp>
 +[HideInInspector]
 +public float mAngle = 0f;
 +</​code>​
 +To create a option menu you will add a class of the next style:
 +<code csharp>
 +using UnityEngine;​
 +using UnityEditor;​
 +using System.Collections;​
 +
 +public class FunWindow : EditorWindow
 +{
 + [MenuItem("​Tools/​Fun Window"​)]
 + public static void ShowWindow()
 + {
 + EditorWindow.GetWindow<​FunWindow>​("​Fun Window"​);​
 + }
 +
 + void OnGUI()
 + {
 + if(GUILayout.Button("​Clear PlayerPrefs"​))
 + {
 + PreferencesManager.DeleteAll();​
 + }
 +
 + if(GUILayout.Button("​Clear Store"​))
 + {
 + Unibiller.clearTransactions();​
 + }
 + }
 +}
 </​code>​ </​code>​
 ==== Coroutines ==== ==== Coroutines ====
fw/unity3d/environtment2d.1396963262.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)