|
I've been trying to start my FPS player off with no weapon. I need him to start off where there is a shot gun on the wall that he can pickup and equip. I added an empty game object to my First Person controller
Which seems to work ok, unless you press fire and then you get a error message. BroadcastMessage Fire has no receiver! UnityEngine.Component:BroadcastMessage(String) PlayerWeapons:Update() (at Assets/WeaponScripts/PlayerWeapons.js:13) I know why but not sure how to fix it so when I have no weapon it's not able to fire. Unless I make it fire nothing and cause no damage to anything, I suppose that might work but it seems to me there is most likely a more proper way to do this? EDIT I put a script on the "NoWeapon" empty game object:
And that got rid of the error because the broadcast fire now has a receiver now, but like I say there is probably a more proper way of doing this?
(comments are locked)
|
|
make it BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver); add that and the error will go away
(comments are locked)
|
|
change the broadcast message to BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver); it will work i had the same problem Dj
(comments are locked)
|

Questions like this make my head hurt. 30 people may read this and have 30 different ideas on what is "right". I like to use object oriented programming and I'm a fan of using NULL to represent the absence of something. So if a player has a "weapon" gameobject, I'd set that to NULL when there is no weapon. That's just me.
if there is no weapon so if its null just let it return instead of doing the fire function. the less functions you have the better it is i think? :) I have made a shooter myself and just said if(weapon){"shoot code"} and weapon is only true when you have got a weapon....
Yeah but I'm not a programmer so there are boat loads of this stuff that I still don't get. I'll bet a lot of my cobbled together work arounds are all wrong according to what's standard with this stuff. I've seen the "Null" code before but am still quite foggy on how to use it. Because I'm an artist my brain works visually so a lot of times unless I can see a working sample of how something is done, it takes me a long time to figure it out. Up until 3 months ago I never touched this code stuff ;)