|
Hi everybody I've made a script which needs 2 variables to work, its own transform and the transform of an prefab with the tag Player. But the script can't reach the transform of the prefab which is instantiated by this script: This script instantiates 3 different prefabs, all with the tag Player. And this is the script which needs the variable othertransform, the transform of 1 prefab with the tag Player: I think the problem is FindWithTag or .GetComponent, but I'm not very sure. Please help me solve this problem!
(comments are locked)
|
|
Look's like your instanciation occurs only when the player presses a button. Problem is, in your Update, you are looking for it all the time. FindWithTag will only look for objects instanciated, in the scene, not the prefab in your project folders. So you should create a public function in the second script to affect those other's variables, and call it from the other script. In the first script's update, check if othertobject is null and leave the function if it is.
(comments are locked)
|
|
Problem solved! Just made a small mistake, said other*t*object instead of otherobject. But I've made classselected static and added if(classselected == true) to the second script right before FindWithTag, just to be safe
(comments are locked)
|

Where is the error raised ? othertransform is null ? Have you tried the function FindGameObjectWithTag ? I'm not quite sure of the difference between the two ...
It just says in the error bar: Variable otherobject has not been assigned. It also displays: Variable othertransform has not been assigned. So I think the mistake is in the FindWithTag function. FindGameObjectWithTag also doesn't work. I'm really sure the Prefab has the tag Player.