So, what I’m trying to accomplish with this piece of script is to access the positions of an array of objects. The objects are already in the array and when I log the individual positions in the for loop, they log correctly in the console, but it gives me the “Object Reference not set to an instance of an object” error.
Here’s the code:
using UnityEngine;
using System.Collections;
public class CylinderChecker : MonoBehaviour {
public GameObject[] Pins;
// Use this for initialization
public int pinCount;
private Vector3[] positions;
void Start () {
for (int i = 0; i < 10; i++) {
Vector3 position = Pins [i].transform.position;
positions [i] = position;
Debug.Log (positions [i]);
}
}
}
The eventual goal of this script is to again access the new positions after they’ve been knocked over and compare that to the original positions from the positions[ ] array in order to count a score for each cylinder knocked over. If there is a better way to do this, I am open to suggestions, but this was what I was working with.
Any feedback would be very helpful.