• 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 Wesley21spelde · Jan 25, 2016 at 11:43 AM · scripting problemweapon systembroadcastmessage

weapons platform broadcastmessage mot working

alt texthey guys i tried to make a weapons pickup

im having problems with the broadcastmessage i would like to make it so that when the player enters the trigger the player gets that weapon

also i wanted to get multiple slots for weapons and than get somthing like chekker boxen weapon 1.2.3 up to 8 or 10 so that i can chek one of them and that wil be the active weapon thats displayed

i was thinking to set all weapons in the slots Enabled false in the player weapons switch en than say hey when i enter the triger i Enable the weapon in my weapon switch

but when i enter the trigger the broadcast message is not working

also how is the weapon switch set to mouse wheel thanks guys

Weapons Platform (See the picture)

 using UnityEngine;
 using System.Collections;
 
 public class WeaponsDepot : MonoBehaviour {
 
     public GameObject player;
     public GameObject[] weapons;
     public GameObject RocketLouncher;
     public Transform ammo;
 
     public int currentWeapon = 0;
 
     private int nrWeapons;
 
     void Start()
     {
 
         nrWeapons = weapons.Length;
 
         SwitchWeapon(currentWeapon); // Set default Weapon
 
     }
 
     void Update()
     {
         for (int i = 1; i <= nrWeapons; i++)
         {
             if (Input.GetKeyDown("" + i))
             {
                // currentWeapon = i - 1;
 
                // SwitchWeapon(currentWeapon);
 
             }
         }
 
     }
 
     void SwitchWeapon(int index)
     {
 
         for (int i = 0; i < nrWeapons; i++)
         {
             if (i == index)
             {
                 weapons[i].gameObject.SetActive(true);
             }
             else {
                 weapons[i].gameObject.SetActive(false);
             }
         }
     }
 
     //Invoked when a button is clicked.
     public void OnTriggerEnter(Collider other)
     {
         //Finds and assigns the child of the player named "Gun".
         //RocketLouncher = other.transform.Find("GunCam").gameObject;
         RocketLouncher.BroadcastMessage("IsRocketLouncher");
 
         //If the child was found.
         if (RocketLouncher != null)
         {
             //Find the child named "ammo" of the gameobject "magazine" (magazine is a child of "gun").
             ammo = RocketLouncher.transform.Find("magazine/ammo");
         }
         else Debug.Log("No child with the name 'Gun' attached to the player");
         Debug.LogError("No child with the name 'Gun' attached to the player");
     }
 }

Switch Weapons /is on a child of my GunCam.

 using UnityEngine;
 using System.Collections;
 
 public class SwitchWeapons : MonoBehaviour
 {
 
     public GameObject[] weapons; // push your prefabs
 
     public int currentWeapon = 0;
 
     private int nrWeapons;
 
     void Start()
     {
 
         nrWeapons = weapons.Length;
 
         SwitchWeapon(currentWeapon); // Set default gun
 
     }
 
     void Update()
     {
         for (int i = 1; i <= nrWeapons; i++)
         {
             if (Input.GetKeyDown("" + i))
             {
                 currentWeapon = i - 1;
 
                 SwitchWeapon(currentWeapon);
 
             }
         }
 
     }
 
     void SwitchWeapon(int index)
     {
 
         for (int i = 0; i < nrWeapons; i++)
         {
             if (i == index)
             {
                 weapons[i].gameObject.SetActive(true);
             }
             else {
                 weapons[i].gameObject.SetActive(false);
             }
         }
     }
     public void IsRocketLouncher()
     {
         currentWeapon = 0;
     }
 
 }


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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

36 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

No Monobehaviour scripts in files 1 Answer

Smooth camera script looking at left hand side of character. 0 Answers

Script and Start function of script are running, but Update function is not? 0 Answers

Changing material on SkinnedMeshRenderer changes on other objects too 1 Answer

I want to make the gameobject rigidbody.iskinematic=true for 3s and immune to damage when it triggers the collider and then false again 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges