- Home /
Duplicate Question
Vector3(x,y,variable)?
Hi friends,
I'm trying to make a following camera for one of my objects (a ball) and I want one of the vectors to be a variable (like a public float I can change from everywhere), but with this code I get an error:
float distance = -10f;
Vector3 whatever = new Vector3 (0,10,distance);
As far as I know, Vector3(float,float,float) for x,y,z but it says: A field initializer cannot reference the non-static field, method, or property.
Any help will be very welcome. Thanks!
This is a C# issue. You can solve your problem by moving the initialization of 'whatever' into Start() or Awake(), or by replacing 'distance' with some static value.
Follow this Question
Related Questions
Keep camera at certain distance from character when rotating 3 Answers
find a world-space coordinate from ScreenPointToRay(Input.mousePosition) raycast 2 Answers
Convert type UnityEngine.Vector3' to float' Error 1 Answer
Add a float to a Vector3 in a direction 1 Answer
Set Distance to object 1 Answer