- Home /
Start FPS player off with no weapon
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
-Main Camera
-Weapons
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:
function Fire() {
}
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?
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 program$$anonymous$$g 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 ins$$anonymous$$d 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 ;)
Answer by moinchdog · Jul 12, 2012 at 01:14 AM
make it BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver); add that and the error will go away
Answer by moinchdog · Jul 12, 2012 at 01:14 AM
change the broadcast message to BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver);
it will work i had the same problem
Dj
Your answer
Follow this Question
Related Questions
picking up weapons script? 3 Answers
FindChild not working? (Pick up Object) 2 Answers
Player Animation change when pickup Weapon 0 Answers
Weapon Pickup and change 2 Answers
Java for android script help??? 0 Answers