- Home /
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;
}
}
}
I am not too sure about rotation my self but when using it I try; Rotation.x rotation.x rotate.x Rotate.x Vector3.right maybe that may help you?
Um, im not sure what you mean. $$anonymous$$d posting the changed code to what your saying? it would help me understand what you mean.
Answer by Eric5h5 · Aug 05, 2012 at 12:56 AM
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.
What would the variable represent?? would it be lightObject.localRotation?
No, localRotation is also a quaternion. The variable would represent the rotation in degrees; see the $$anonymous$$ouseLook script in the character controller standard package for an example of a script that uses its own variables to track rotation of specific axes ins$$anonymous$$d of trying to read it from the object (which is fairly problematic).
Alright. I see what you mean. But could you post an example? or if your bored perhaps a fix? becuase it will help me understand what you mean. Also, in the mouse look script, im guessing you mean these variables.
public enum RotationAxes { $$anonymous$$ouseXAndY = 0, $$anonymous$$ouseX = 1, $$anonymous$$ouseY = 2 } public RotationAxes axes = RotationAxes.$$anonymous$$ouseXAndY; public float sensitivityX = 15F; public float sensitivityY = 15F;
public float $$anonymous$$imumX = -360F; public float maximumX = 360F;
public float $$anonymous$$imumY = -60F; public float maximumY = 60F;
float rotationY = 0F;
Answer by slayer29179 · Aug 05, 2012 at 12:41 AM
Sure :) 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 :)
Actually none of those is correct, sorry...see my answer for an explanation.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
C# Unity 3D Lock Rotation but allow Rotation of Parent Object 1 Answer
qrest system 1 Answer
Help with movement script 2 Answers
Temporary Rotation 2 Answers