Setting a variable using ViewportToWorldPoint
Having trouble setting a variable using this code. The xmin and max are later used to clamp movement to the xaxis in the player space.
At the moment debug logs are returning the vales as what they were initially set too.
There is only 1 camera in the scene tagged as maincamera.
Any ideas on what might be wrong? nothing I am trying seems to work.
private float xmax = 5;
private float xmin = -5;
void start(){
Camera camera = Camera.main;
float distance = transform.position.z - camera.transform.position.z;
xmin = camera.ViewportToWorldPoint (new Vector3 (0, 0, distance)).x;
xmax = camera.ViewportToWorldPoint (new Vector3 (1, 1, distance)).x;
}
Answer by Asgardr · Jul 03, 2016 at 02:21 PM
C# is a case-sensitive language. In simple terms this means that according to the C# compiler:
void start()
and
void Start()
Are two completely different functions. Unity is using reflection to look for a function called Start(), not start(). Therefore, the function you've defined in code will not be called.
If you change your function to be capitalized, everything should work correctly.
Your answer
