- Home /
Script doesn't find other script
I am instantiating a prefab when I press "T" and when I walk over it it is supposed get destroyed, which it does. But the issue is that the instantiated prefab doesn't assign the script that it changes a variable of. How do I make it so that it assigns the script once it has been instantiated?
Here's my script: var Tact : ThrowTact;
function Start () {
}
function Update () {
Tact = GetComponent(ThrowTact);
}
function OnTriggerEnter (Other : Collider) {
if(Other.gameObject.tag == "Player"){
Destroy(gameObject);
Tact.HasTact = true;
}
}
Out of curiosity - what is the reason behind setting HasTact to true, if the object has just been marked to be destroyed?
Besides, calling GetComponent every frame is just overkill. If you need it only in OnTriggerEnter, then retrieve it there. If you need it in another place, assign Tact in Awake or Start.
Your answer
Follow this Question
Related Questions
Collision, change skybox in game 1 Answer
Door open/load level java script troubles 1 Answer
Action activates trigger. 1 Answer
Have script detect which collider 2 Answers
Script crashes Unity 1 Answer