- Home /
The variable othertransform of Prefab has not been assigned
Hi everyone
I want to make a GUI button which instantiates a prefab which uses the distance between the player and the prefab itself to modify variables. But when I try to assign the variable othertransform, the transform of the player, the inspector doesn't recognize it. So, how do I assign the variable othertransform from within a script. My player is just the original 3rd Person Controller and it has a tag called Player. These are my scripts: This is the object I want to instantiate
var mytransform : Transform;
var othertransform : Transform;
function Update (){
if(Vector3.Distance(mytransform.position, othertransform.position) < 100){
AttackScript.interval = 3;
MpBasedAttackScript.interval = 5;
}
else{
AttackScript.interval = 5;
MpBasedAttackScript.interval = 10;
Destroy (gameObject);
}
}
And this is the script I use to generate my button and to instantiate the prefab:
var instantiatedobject : GameObject;
var spawnplace : Transform;
function OnGUI () {
if(GUI.Button(Rect(200,500,100,100),"Buffspring")){
var instance : GameObject = Instantiate(instantiatedobject, spawnplace.position, spawnplace.rotation);
}
}
Please help me solve this problem.
Perhaps try:
othertransform = GameObject.Find("3rd Person Controller");
Answer by Romano185 · Apr 28, 2012 at 01:06 PM
I just instantiated a trigger. When the player enters the trigger the variable is changed. I still don't know why I wanted to use Vector3.distance. It works terrible for me, triggers are way better to use.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063610im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make sprites instantiate based on randomly generated integer? 1 Answer
Problem with GetComponentinChildren and Instantiate 0 Answers
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer
Howto set main.camera as a parent when main.camera itself is a child of a prefab 1 Answer