x


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.

more ▼

asked Jan 31 '12 at 07:48 PM

Romano185 gravatar image

Romano185
35 13 20 22

Perhaps try:

othertransform = GameObject.Find("3rd Person Controller");

Jan 31 '12 at 09:35 PM merry_christmas

Your solution didn't work, but I solved it already.

Feb 02 '12 at 06:53 PM Romano185
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Fine! Please don't tell me how. I could need it x__x

more ▼

answered Apr 25 '12 at 07:00 AM

daboom gravatar image

daboom
0

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 28 '12 at 01:06 PM

Romano185 gravatar image

Romano185
35 13 20 22

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1682
x1281
x1260
x302
x92

asked: Jan 31 '12 at 07:48 PM

Seen: 697 times

Last Updated: Apr 28 '12 at 01:06 PM