[Solved] Changing Ship/Paddle Sprite w/powerUp?

Hello guys,

I thought that I had came up with a method of changing the hero sprite/ship/paddle/bat whatever you wish to call it by accessing the SpriteRenderer and changing to the appropriate index of the sprite using this code:


However using the above code I get the following error:

  1. NullReferenceException: Object reference not set to an instance of an object
    PaddleMove.Update () (at Assets/Scripts/PaddleMove.cs:46)

For some reason the line Number at Pastebin is slightly different to actual code (??) and the problem is really on Line 44. And I can’t understand why it is throwing up this problem. Woulld any of you guys know what the problem is and how to rectify it?

Thankyou in advance.


Well it seems there is no object at that position in the array. Have you hooked it up correctly?


I just found the error it was a matter of defining the SpriteRenderer twice. It should have been set as a class-wide variable but because of the structure of the code in line 24 the SpriteRenderer became only a function wide variable :blush:. So, the compiler got upset with me trying to use the SpriteRenderer in the Update function :smile:.

I really don’t know why it took me so long to see it.

Privacy & Terms