x


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?

more ▼

asked May 12, 2011 at 07:00 PM

Michael 12 gravatar image

Michael 12
132 273 191 202

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.

May 12, 2011 at 07:37 PM flaviusxvii

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....

May 12, 2011 at 08:02 PM ruben_hiet

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 ;)

May 12, 2011 at 08:44 PM Michael 12
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

make it BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver); add that and the error will go away

more ▼

answered Jul 12, 2012 at 01:14 AM

moinchdog gravatar image

moinchdog
61 18 18 18

(comments are locked)
10|3000 characters needed characters left

change the broadcast message to BroadcastMessage("Fire", SendMessageOptions.DontRequireReceiver);

it will work i had the same problem

Dj

more ▼

answered Jul 12, 2012 at 01:14 AM

moinchdog gravatar image

moinchdog
61 18 18 18

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x350
x233
x13
x3

asked: May 12, 2011 at 07:00 PM

Seen: 1569 times

Last Updated: Jul 12, 2012 at 01:14 AM