Last active
July 28, 2017 03:53
-
-
Save tklee1975/80abd24ef20b6eac031f99c4080a3dd3 to your computer and use it in GitHub Desktop.
Instantiate() vs Awake() vs Start()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void testCreateObject() // Testing Instantiate | |
| { | |
| float x = Random.Range(-3, 3); | |
| float y = Random.Range(-3, 3); | |
| Vector3 position = new Vector3(x, y, 0); | |
| Debug.Log("Before Instantiate"); | |
| GameObject obj = GameObject.Instantiate(sourceObject, position, Quaternion.identity); | |
| Debug.Log("After Instantiate"); | |
| obj.transform.SetParent(playSpace); | |
| Debug.Log("After SetParent"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class TestObject : MonoBehaviour { | |
| private bool mIsFirstUpdate = true; | |
| void Awake () { | |
| Debug.Log("TestObject: Awake"); | |
| } | |
| // Use this for initialization | |
| void Start () { | |
| Debug.Log("TestObject: Start"); | |
| } | |
| // Update is called once per frame | |
| void Update () { | |
| if(mIsFirstUpdate) { | |
| Debug.Log("TestObject: First Update"); | |
| mIsFirstUpdate = false; | |
| } | |
| } | |
| void OnEnable () { | |
| Debug.Log("TestObject: OnEnable"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment