- Home /
Calling a variable in C#?
Hey, so im trying to learn C#, i previously used Javascript so this is new to me. Im trying to call a variable that represents: "transform.right * 20" this is what i used.
public rgt transform.right * 20;
That doesnt work. What can i do to make this right?
unityGE$$anonymous$$S.com for explantion of basics with variables, etc
Answer by aldonaletto · Oct 27, 2012 at 01:55 AM
You should declare the variable type before its name and place an = after it:
public Vector3 rgt = transform.right * 20;
But this would not work anyway because you can't initialize member variables with game object properties: you should just declare the variable, then initialize it at Awake or Start:
public Vector3 rgt;
void Awake(){
rgt = transform.right * 20;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Variable References in C# from JS 1 Answer
can't read updated variable 2 Answers
Call a method whenever the assigned variable gets altered 2 Answers