Here is my code.
This is what i am trying to do. When a brick is destroyed i want to instantiate the same brick after five seconds but it doesnt do that. when i run it doesnt instantiate and i dont know why. please help!!!
var scoreValue : int;
var gameController1 : GameController1;
var brickParticle : Transform;
var brick : GameObject;
var box : BoxCollider2D;
var restartDelay : float = 5f;
private var restartTimer : float;
function Awake() {
box = GetComponent.<BoxCollider2D>();
box.enabled = true;
}
function Start () {
var gameControllerObject : GameObject = GameObject.FindWithTag ("GameController1");
if (gameControllerObject != null) {
gameController1 = gameControllerObject.GetComponent (GameController1);
}
if (gameController1 == null) {
Debug.Log ("Cannot find 'GameController1' script");
}
}
function OnCollisionEnter2D(coll : Collision2D) {
gameController1.AddScore (scoreValue);
Instantiate(brickParticle, transform.position, transform.rotation);
Instantiate();
Destroy(gameObject);
}
function Instantiate() {
restartTimer += Time.deltaTime;
if(restartTimer >= restartDelay) {
Instantiate(brick, brick.transform.position, brick.transform.rotation);
}
}
@Mmmpies so like this. function OnCollisionEnter2D(coll : Collision2D) { gameController1.AddScore (scoreValue); Instantiate(brickParticle, transform.position, transform.rotation); //Instantiate(); Destroy(gameObject); } function Update() { restartTimer += Time.deltaTime; if(brick == null && restartTimer >= restartDelay) { Instantiate(brick); } } function Instantiate() { }
– Mansmart10It still doesn't work.
– Mansmart10that just overflows my hierarchy with bricks and particles. and crashes unity.
– Mansmart10