Hey there ![]()
The below codes gives a weird error in line 38 which is this line in the below:
positions[i] = new Vector3(Input.mousePosition.x,Input.mousePosition.y,Input.mousePosition.z);
it gives the error:
NullReferenceException: Object reference not set to an instance of an object
at TrackPosition.Update () [0x0002c] in I:\Minimap\Assets\TrackPosition.cs:38
And I have no idea what to do. linePrefab IS set in unity, and the arrays do have a defined length. After abit of testing, I came to the conclusion that my for-loop is bugged. Maybe some of you can tell me otherwise. ![]()
using UnityEngine;
// Update is called once per frame.
void Update () {
if (!tracking)
{
if (Input.GetMouseButtonDown(0))
{
for (int i = 0; i < 10; i++)
{
Debug.Log(Input.mousePosition);
positions[i] = new Vector3(Input.mousePosition.x,Input.mousePosition.y,Input.mousePosition.z);
positions[i].z = 40;
worldPos[i] = new Vector3(
Camera.main.ScreenToWorldPoint(positions[i]).x,
Camera.main.ScreenToWorldPoint(positions[i]).y,
40);
Instantiate(
linePrefab,
worldPos[i],
Quaternion.Euler(
0,
0,
Divide(
Substract(worldPos[i - 1].x, worldPos[i].x),
Substract(worldPos[i - 1].y, worldPos[i].y))));
}
}
}
}
Please help me! ):
EDIT: Substract and Divide are functions that does exactly what the name suggests.
~Mikkelet