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.