Getting a variable from another script

I have a bullet prefab which i instantiate from my “maincharacterscript” script

with the “bulletscript” which i have put on my bullet prefab i do the following to get the variable from my “maincharacterscript” script

var aimspeed : Transform;

var otherscript_aimspeed : characterscript; // (in variables declarations)

otherscript_aimspeed=aimspeed.GetComponent(maincharacterscript); //  (in update)

otherscript_aimspeed.aimspeed //then i call the variable

I havent forgot to move the transform object over to aimspeed in the inspector, thats ok

my problem is, it doesnt update the aimspeed value…
could this be because the prefab i assigned over in the inspector was a prefab of my character and not the one in the hierarchy? as i couldnt assign that…

Thanks for any help

line 6 and 8 needs to be inside a function like start/awake or line 8 could be in update if you need constant updates.

if line 4 is referring to a prefab you need to instantiate it first then get the reference to the instance’s components

1 Like

ok thanks for that, i think the problem is line 4 then, its such a pain just to copy this variable over :frowning:

Thanks