Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Last active July 28, 2017 03:53
Show Gist options
  • Select an option

  • Save tklee1975/80abd24ef20b6eac031f99c4080a3dd3 to your computer and use it in GitHub Desktop.

Select an option

Save tklee1975/80abd24ef20b6eac031f99c4080a3dd3 to your computer and use it in GitHub Desktop.
Instantiate() vs Awake() vs Start()
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");
}
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