|
This script is in a prefab. When I run the script, Unity says... "NullReferenceException: Object reference not set to an instance of an object"
Any help would be greatly appreciated.
(comments are locked)
|
|
Make sure that your camera is tagged as MainCamera, or "Camera.main" won't work. Otherwise, I've verified that your script is fine. Although, you could simplify it to:
(Note that you don't even need the campos variable, but for readability you could easily justify keeping it) Didn't realise you could double up your '='s there. Nice. My camera is tagged as MainCamera, but sadly the bug still remains.
Sep 23 '10 at 07:12 AM
Billamu
Are you sure that the error is about the ScreenToWorldPoint line? If you comment it out, does the error still occur? If I put this code into an empty script on a new object, it works fine.
Sep 23 '10 at 07:30 AM
Marowi
I've been tinkering with things and I've found that the prefabs were originally in the Heirachy; I was using an object pool on them. I've found that when I revert to instantiating the prefabs the problem goes away.
Sep 23 '10 at 08:35 AM
Billamu
Glad you solved it - sorry that I couldn't help, beyond telling you that your script was fine!
Sep 23 '10 at 08:40 AM
Marowi
(comments are locked)
|

I've assumed the error is pointing to the line where you're calling 'Camera.main.ScreenToWorldPoint(campos);' If that's incorrect, please update your question to clarify! Cheers.