- Home /
Object refernce not set to an instance of an object ....
before i ask this question , I HAVE looked at answers but none of them quiet fit the same sort of problem as mine .... Any way I have a little bit of my code here , im calling my RayShoot function to my other script called camshake ( for camera shake when i shoot ) but i cant figure out whats wrong. ( BTW its little bits of my code , all the braces are correct )
var other : camshake;
other = gameObject.GetComponent("camshake");
function Start () {
BulletsLeft = BulletsPerClip;
muzzleFlash.emit = false;
PHitParticle.emit = false;
}
function Update (){
other.RayShoot ();
if( KeyTimer > 0){
KeyTimer -= Time.deltaTime;
}
function Update (){
other.RayShoot ();
if( KeyTimer > 0){
KeyTimer -= Time.deltaTime;
}
Answer by Azrapse · Oct 09, 2013 at 08:48 AM
Well. That error means that you are trying to access a member of a null reference. It should give you the specific line number where it happens, and you should give it to us, but I will guess...
It could be other.RayShoot()
if other
is null. And that could be null because other = gameObject.GetComponent("camshake");
cannot find a component of type camshake
.
Are you sure the type name is spelled exactly like that?
Using the debugger is usually the answer to all your NullReferenceException
s. Place a breakpoint on the erroneous line and examine the value of all involved variables within the debugger.
Open the Cam Shake script and check the name of the class there. You must use that spelling.
Other than you mistyping the name of the component type, it could be that you are trying to get the Cam Shake component from the wrong game object. Without knowing your script structure any deeper I cannot help you more.
Your answer
Follow this Question
Related Questions
How to Touch Drag 3D Objects 2 Answers
Manipulating Instanced Object 2 Answers
destroy object after a delay? 6 Answers
CCG: Creating a card object 2 Answers