Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Michael 12 · May 12, 2011 at 07:00 PM · weaponpickupruntime-error

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flaviusxvii · May 12, 2011 at 07:37 PM 0
Share

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.

avatar image ruben_hiet · May 12, 2011 at 08:02 PM 0
Share

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

avatar image Michael 12 · May 12, 2011 at 08:44 PM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by moinchdog · Jul 12, 2012 at 01:14 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges