I get a NullReferenceException when I press my "action" button and the object is within range. This is the script I based it off of, but instead I'm finding the tag not the name: I have no idea what I did wrong can someone help?! Thanks!
(comments are locked)
|
|
These 2 lines: should be: Ya beat me to it!
Jun 23 '11 at 12:08 AM
DaveA
You could also use the CompareTag() instead of a string comparison which is a little bit faster.
Jun 23 '11 at 12:16 AM
save
Ok thanks I cant belive u spotted that!
Jun 23 '11 at 12:19 AM
MrSplosion
I've missed it also the first time :D but that kind of flaws are quite regular recently, so we are kinda prepared :D As I said you should get an compiler error on this issue...
Jun 23 '11 at 03:23 AM
Bunny83
(comments are locked)
|
|
I'm guessing hit.collider.GameObject.tag should not capitalize gameObject
(comments are locked)
|

There are only 3 things that I can think of inside your code that could possibly cause a problem:
1)In
Update(), you are using Camera.main.transform, but inPickUpWeapon(), you are usingcameraVar.Make sure thatcameraVaris assigned or just change it to Camera.main2) In the unity scripting reference, it says that
hit.collidercan be null if the raycast didn't hit anything. Tryif(hit.collider == null) print("miss"); else...3) This should be fine, but it's bugging me: you're passing the raycast into a variable instead of directly into an if statement like I normally see. I might be optimizing the null loop here, but try passing it directly into the if and avoiding the
var rayVar = ....@MrSplosion: Didn't you get compiler errors on that? Something like "GameObject is not part of UnityEngine.Collider".
@SilverTabby: