#how do you get a varible from another script to a new script
1 messages ยท Page 1 of 1 (latest)
unity
yeah i watched that video already it didnt really work
show code
general steps:
1.) your script has to get the component/script attached to another object
2.) once you have the component, you have to get it with .VariableName
ok give me a sec
make sure that .VariableName is public
๐
oky i will try
and how do i get the variable
GetComponent<Portalpont>() will get the script, so now you have to add .pointadd to it
Portalpont theComponent = GetComponent<Portalpont>();
int theVariable = theComponent.pointadd;
and i put all of that in void start??
are you trying to keep the values in both scripts synced?
if you put it in the start it will copy the value once
theComponent.pointadd instead
what does the error say?
you also don't need the last one, just do theComponent.pointadd
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
what last one
it's erroring because you need to do something with the value, like +=
you already got the component through theComponent. it's stored there. you can just do theComponent.pointadd += point
