What is wrong with this script?

i keep getting this error with this script. “NullReferenceException: Object reference not set to an instance of an object” This is supposed to be in javascript… in case i did something wrong, language-wise.

its something with the “if(lightObject.transform.Rotation.x > 31){” but i dont know what im doing wrong.

Please help!

Heres the code:

var lightObject : GameObject;
var breathingObj : GameObject;
var hasSprinted : boolean = false;

function Update () {

if(breathingObj.GetComponent(SprintScript).isSprinting == true){

 lightObject.transform.Rotate(Time.deltaTime * 50, 0, 0);
 
 hasSprinted = true;

 if(lightObject.transform.Rotation.x > 31){
 
 lightObject.transform.Rotation.x = 31;
 
 hasSprinted = true;
 
 }
 }
 
else if(breathingObj.GetComponent(SprintScript).isSprinting == false && hasSprinted == true){

 lightObject.transform.Rotate(Time.deltaTime * -50, 0, 0);
 
 if(lightObject.transform.Rotation.x > 0){
 
 lightObject.transform.Rotation.x = 0;
 }
 }
}

There’s no such thing as transform.Rotation. Capitalization is very important. Also, that won’t work even when corrected, since transform.rotation is a quaternion, which is a 4-dimensional representation of an object’s rotation, so rotation.x doesn’t correspond to the x axis and is not in degrees anyway. Since reading one component from eulerAngles tends to be unreliable (since there’s more than one valid way to represent an object’s rotation), you’re better off tracking the rotation yourself in a separate variable.

Sure :slight_smile: Try These;

if(lightObject.transform.Rotation.x > 31){

if(lightObject.transform.rotation.x > 31){

if(lightObject.transform.Rotate.x > 31){

if(lightObject.transform.rotate.x > 31){

if(lightObject.transform.Vector3.right > 31){

and see if they work :slight_smile: