✅ Variable access help :(
I have an object named player and I'm trying to access a variable, an int, called speed and I've been told to use "GetComponent" although when I use it I'm a tad bit confused on how to access the variable?
"speed = player.GetComponent<speed>();" is what I tried which didn't work.
17 Replies
speed is not a component, it is a variable / field.
oh so I put the script I'm trying to access in the <>
Components are classes that inherits MonoBehavior
You can access speed directly.
Since it lives within the same class
oh shoot
the speed in phones isn't what I'mt rying to access
trying to access this speed
which is in basic movement in a seperate script
I see. Then you use
GetComponent<BasicMovement>()
It is the name of the class / componentah ok
that worked but then how do I get access to the individual variables?
Then you can access
speed
from thereso it's entirely connected now?
or atleast the publics are?
And then you can access speed by doing
movement.speed
oh ok
If it lives on the same object in the hierarchy
I understand now, thanks 🙂
should I delete my post now or do I just leave it
$close
If you have no further questions, please use /close to mark the forum thread as answered
ah cool thanks again