Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
fw:unity3d:environtment2d [2014/04/24 13:27] alfred [Working with mobile phones] |
fw:unity3d:environtment2d [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| 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 265: | Línea 281: | ||
| * ''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''. | * 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 272: | 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 ==== | ||