Hi all,
I’m having problem with creating simple script that just adds spheres on left mouse click and deletes them on right click. I get this error: “NullReferenceException: Object reference not set to an instance of an object SphereCreator.Update () (at Assets/SphereCreator.js:18)”. What is wrong?
Here is the script:
var sphere : GameObject;
var sphereCounter : int = 0;
var sphereArray : Array;
function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.Mouse0))
{
sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphereCounter++;
sphere.transform.position = Vector3(0, sphereCounter, 0);
sphereArray.push(sphere);
}
if(Input.GetKeyDown(KeyCode.Mouse1))
{
if(sphereCounter>0) Destroy(sphereArray[sphereCounter-1]);
}
}