Getcomponent Not Recognising Component In Unity Javascript Code
I have a code block that starts a timer, enables a script, instantiates, then disables that script (this makes my game mechanic work out). The only issue I'm facing now is my Javas
Solution 1:
The script
variable is not declared.
#pragma strictvar enemy : Transform;
privatevar timer : float;
publicvar mother : GameObject;
//DECLARE ITprivatevar script : triggered;
function Awake() {
timer = Time.time + 14;
script = mother.GetComponent(triggered);
script.enabled = script.enabled;
}
function Update() {
if (timer < Time.time) {
Instantiate(enemy, transform.position, transform.rotation);
timer = Time.time + Random.Range(55, 60);
script.enabled = !script.enabled;
}
}
Note:
Please learn C# and start using it in Unity. You will save yourself your time. Also, when creating scripts make sure to capitalize them. For example, triggered
should be Triggered
.
Post a Comment for "Getcomponent Not Recognising Component In Unity Javascript Code"