I am new to Programming in Unity3D (JavaScript) but I have been programming in Java for about a year now and have had experience in other languages, so I consider myself a decent programmer. But recently I have been getting a good amount of errors from Unity that I can not find out. This one has been bothering me the most:
NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)
jsStart.BuildPins () (at Assets/jsStart.js:74)
jsStart.Start () (at Assets/jsStart.js:29)
I understand what it means, but not WHY I am getting it. Here is the code where the error occurs:
function BuildPins(){
var currentPin : GameObject;
for(var i : int = 1; i <= 10;) {
currentPin = Instantiate(bowlingPin,Vector3(startX,startY,startZ),transform.rotation);
currentPin.transform.position.y = startY;
if(i == 1){
} else if (i >= 2 && i <= 3){
if(i == 2){
currentPin.transform.position.x = secondX;
currentPin.transform.position.z = secondZ;
} else {
currentPin.transform.position.x = pins*.transform.position.x;*
_ currentPin.transform.position.z = -pins*.transform.position.z;_
_ }_
_ } else if (i >= 4 && i <= 6){_
_ if(i == 4){_
_ currentPin.transform.position.x = thirdX;_
_ currentPin.transform.position.z = thirdZ;_
_ } else {_
_ currentPin.transform.position.x = pins.transform.position.x;
currentPin.transform.position.z = pins.transform.position.z - 0.3368112;
}
} else if (i >= 7 && i <= 10){
if(i == 7){
currentPin.transform.position.x = fourthX;
currentPin.transform.position.z = fourthZ;
} else {
currentPin.transform.position.x = pins.transform.position.x;
currentPin.transform.position.z = pins.transform.position.z - 0.3368112;
}
}
currentPin.transform.rotation.x = 270;
currentPin.transform.rotation.y = 0;
currentPin.transform.rotation.z = 0;*_
* pins[i-1] = currentPin;//ERROR IS HERE*
* print(i.ToString);*
* }*
}
I am trying to make a function that will basically set up a pyramid of Bowling pins in a specific place without having to do too much hardcoding (hence the for statement and subtraction and adding off positions). I don’t even get through it once because the debug does not print any numbers (i.ToString).
Any help will be appreciated. ![]()
Thanks,
Brandon