- Home /
JS Automaticly Unchecked Upon Instantiate
So I have this endless jumper game where a platform (that you jump on) gets destroyed and Instantiateed to a new place once it is out of the view of the camera. However the Instantiated objects have the script that is used to flipp them unchecked. This is obviously big problem since they will nolonger be destroyed and Instantiated when out of view of the camera. Here is the script that is attached to the platforms:
pragma strict
var y : GameObject;
var x : GameObject;
var random : Vector3;
function OnTriggerEnter (looper : Collider) {
if(looper.name == "player")
{
Destroy(y);
random = Vector3(Random.Range(-2.5, 2.5),(transform.position.y + 8),0);
Instantiate(this.y, random, transform.rotation);
if(Time.timeScale > 1)
{
Time.timeScale -= 0.1;
}
}
}
function Update ()
{
if(transform.position.y < x.transform.position.y - 2)
{
Destroy(y);
var random = Vector3(Random.Range(-2.5, 2.5),(transform.position.y + 8),0);
var object = Instantiate(this.y, random, transform.rotation);
}
}
Sooo..... check it?
Not every script needs an Update. You can simply have a custom function and refer to that to perform your operation. This way you can leave your script enabled (in the prefab).
Your answer
Follow this Question
Related Questions
Unexpected token: private. Error. Can anyone help? 2 Answers
error help (Javascript) 0 Answers
Command "GetButton" not working well 2 Answers