- Home /
C# access another C # without using "GetComponent"?
Is that possible a C # access a variable in another C # without using "GetComponent"? Making the same way as is possible in JavaScript, which simply just put the script name + variable name (static). My problem is, I have a scene with a C# that should update a variable in another C# on a GameObject in another scene. I looked for a way to direct access from C # but not found. Thank tips.
Answer by fafase · Jul 11, 2013 at 01:53 PM
ScriptName.member
works also in C# but it is static. UnityScript has the exact same functioning, you were just using static variables.
For instance members, use GetComponent
Make sure you know what static is before using it.
Wow! Simple like this: public static int carPower = 10;(On C#) or static var carTorque: int = 66; (On Java). Just putting the scripts on different folders.
Yes but understand that if you place that script on different cars they all are having the same speed.
One variable to rule them all (Epic voice).
For all car to have their own speed you need an instance member that you have to access using GetComponent.
Your answer
Follow this Question
Related Questions
Is it possible to change a variable, into a script not assigned to any game object? 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Access and Change variables from other Scripts? 2 Answers
Another way to reference scripts? 2 Answers
Assigning varaibles to prefabs 1 Answer