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 · Feb 14, 2011 at 12:07 AM · javascriptarrayweapon

I'm trying to add a 3rd and possible more weapons to this script what am I missing??

I'm trying to add a 3rd and possibly more weapons to this script but I keep getting a message asying that "BroadcastMessage Fire has no reciver" whatever that means, and yes before you ask I'm new to this whole scripting stuff, model building is more my bag of tricks, but I'm trying to learn something new. Here is my script:

function Start () { // Select the first weapon SelectWeapon(0); }

function Update () { // Did the user press fire? if (Input.GetButton ("Fire1")) BroadcastMessage("Fire");

 if (Input.GetKeyDown("1")) {
     SelectWeapon(0);
 }   
 else if (Input.GetKeyDown("2")) {
     SelectWeapon(1);
 }
 else if (Input.GetKeyDown("3")) {
     SelectWeapon(2);
 }   

}

function SelectWeapon (index : int) { for (var i=0;i<transform.childCount;i++) { // Activate the selected weapon if (i == index) transform.GetChild(i).gameObject.SetActiveRecursively(true); // Deactivate all other weapons else transform.GetChild(i).gameObject.SetActiveRecursively(false); } }

Any help on this would be greatly apreciated :)

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Jason_DB · Feb 14, 2011 at 01:10 AM

Broadcastmessage("Fire") looks for a function called 'fire' in an object or any of it's children, and then calls it. 'BroadcastMessage Fire has no receiver' means that the message you're broadcasting can't find a function called 'fire', so you're probably missing a script on the gun. I would check again to make sure your 3rd gun has all the proper scripts on it, or even start by duplicating the second and then tweaking it.

Comment
Add comment · Show 3 · 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 Michael 12 · Feb 14, 2011 at 03:09 AM 0
Share

Yup, that was it, now if I can just figure out why my grenade launcher is not causing any damage when basically it has the same script that the rocket launcher has :doh:

avatar image Michael 12 · Feb 14, 2011 at 02:58 PM 0
Share

Figured it out, my Explosion from the detonator add on pack was missing the java script that enabled it to give damage... lol it's always the simple things eh? ;)

avatar image Michael 12 · Feb 15, 2011 at 12:55 PM 0
Share

Now I can't seem to get my 3rd weapon which is the Grenade launcher to work with their part of the GUI tutorial, I've tried tweaking those varialble to no end and it keeps giving me an error in the "FPSPlayer.js" that reads: Assets/WeaponScripts/FPSPlayer.js(15,31): BCE0018: The name 'GrenadeLauncher' does not denote a valid type ('not found').

Now in my First person Controller game object's weapons my grenade launcher is named thusly:

Launcher -GrenageLauncher (all the parented ojects under that as I'm using my own custom model)

I can't figure out what i'm missing??

avatar image
0

Answer by BadProxy Latzo · Feb 16, 2012 at 03:41 PM

The file containing the code "BroadcastMessage Fire" must be equal to or a child of the file that contains the method Fire(), otherwise the BroadcastMessage won't find the method.

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

Adding an object to an array of custom objects (JS) 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Push Custom Class to Array (JavaScript) 1 Answer

Array of custom class objects all return the same value? 1 Answer

Sorting by multiple variables 3 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