- Home /
referencing floats in a vector3
I am new to unity and am trying to use a float inside a vector3 but this won't work.
public float height = 12;
public Vector2 rangeVector = new Vector2(0 , height);
I don't know why it doesn't work but any help would be great.
"it doesn't work" is quite vague. are you getting any error messages? if so, it's a good idea to include them...
for this, it's quite likely that the error relates to your definition of height
. try this:
public float height = 12f; // the f tells the compiler it's a float
Answer by Jessespike · May 13, 2015 at 04:05 PM
Can't initialize a field with a nonstatic reference.
Either make height a static field, ie:
public static float height = 12;
Or better yet, move the rangeVector initialization into Awake/Start
void Awake() {
rangeVector = new Vector2(0 , height);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613195500im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I want to move a rigid object with following command 1 Answer
Velocity value changes way to drastically when position quickly changes 0 Answers
Convert type UnityEngine.Vector3' to float' Error 1 Answer
How can I replace this Vector3 with a float? 2 Answers
get Pitch and Roll values from object 3 Answers