|
How do you reference an instance of a GameObject "hit" via RaycastHit? I would assume it's this
(comments are locked)
|
|
Is your raycast actually hitting a collider/rigidbody? Else the nullreference would be obvious ;) if you're unsure how to test this just use if(physics.Raycast(etc)) which returns true if it hits something and false if it does not. If you're sure that's not it, alternatively try using hit.collider.gameObject, which I have used successfully in the past. This wouldn't explain why hit.transform.gameObject does not work, though. hit.gameObject.name returns the right object name...
May 07 '11 at 04:20 AM
ina
Are you perhaps constantly rdeclaring the variable hit and re-casting your ray without checking if it intersects or not? Because that would explain it sometimes working and sometimes throwing a NullReferenceException
May 07 '11 at 04:24 AM
Joshua
i am constantly redefining hit, but each time, it's assigned to a global... the hit occurs only after the if(Physics.RaycastHit) ... so hit has to have hit an object each time
May 07 '11 at 04:29 AM
ina
It looks like this has to do with how I didn't reference the right object that contains the script component.. mea culpa!
May 07 '11 at 06:51 AM
ina
(comments are locked)
|
