• 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 /
  • Help Room /
avatar image
0
Question by melis18 · May 26, 2017 at 09:48 AM · script.weapondrop

I need Drop Weapon Scripe

Hello,I realy need script for droping weapons. This is my Weapon Pick up script public class WeaponPickup : MonoBehaviour {

     public string weaponName = "M9";
     //public string pickupName = "M9";
 
     private GameObject weaponManagerObject;
     private WeaponManager weaponManagerScript;
 
 
     private void Start()
     {
         weaponManagerObject = GameObject.FindGameObjectWithTag("WeaponManager");
         weaponManagerScript = weaponManagerObject.GetComponent<WeaponManager>();
     }
 
     public void Interact()
     {
         if (weaponManagerScript.hasWeapon == false)
         {
             GameObject weaponFound = weaponManagerObject.transform.FindChild(weaponName).gameObject;
             weaponFound.SetActive(true);
             Destroy(gameObject);
             weaponManagerScript.hasWeapon = true;
         }
         
 
 
     }
     
     
 }


and its attaced to script intarect

 public class Interact : MonoBehaviour
 {
 
     public float interactRange = 3f;
     public bool debugRay = false;
     public KeyCode interactKey = KeyCode.E;
     public KeyCode dropKey = KeyCode.F;
     public Camera FPSCamera;
 
     public Text interactText;
 
     private FoodItem foodItem;
     private Player player;
 
     private Inventory inventory;
 
     private object weaponPickup;
 
     private object weaponDrop;
 
 
     private void Start()
     {
         player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
         inventory = GameObject.FindGameObjectWithTag("Inventory").GetComponent<Inventory>();
         
     }
 
 
 
     private void Update()
     {
         Ray ray = FPSCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
         RaycastHit hitInfo;
 
         interactText.text = ("[" + interactKey + "]" + " Interact");
 
         if (debugRay == true)
         {
             Debug.DrawRay(ray.origin, ray.direction * interactRange, Color.yellow);
         }
 
         if (Physics.Raycast(ray, out hitInfo, interactRange))
         {
             if (hitInfo.collider.gameObject.layer == 8)
             {
                 interactText.enabled = true;
             }
             else if (hitInfo.collider.gameObject.layer != 8)
             {
                 interactText.enabled = false;
             }
 
             if (Input.GetKeyDown(interactKey))
             {
                 if (hitInfo.collider.tag == "FoodItem")
                 {
                     foodItem = hitInfo.collider.GetComponent<FoodItem>();
 
                     if (foodItem.hungertype == FoodItem.HungerType.Food)
                     {
                         player.AddHunger(foodItem.amountToAdd);
                         inventory.AddItem(1);
                         inventory.AddItem(2);
                         foodItem.DestroyObject();
                     }
                     else if (foodItem.hungertype == FoodItem.HungerType.Water)
                     {
                         player.AddThirst(foodItem.amountToAdd);
                         inventory.AddItem(3);
                         foodItem.DestroyObject();
                     }
                 }
             
                 else if (hitInfo.collider.tag == "WeaponPickup")
                 {
                     WeaponPickup weaponPickup = hitInfo.collider.GetComponent<WeaponPickup>();
                     weaponPickup.Interact();
                 }
                 else if(hitInfo.collider.tag == "AmmoPickup")
                 {
                     AmmoPickup ammoPickup = hitInfo.collider.GetComponent<AmmoPickup>();
                     ammoPickup.Interact();
                 }
                 
                
             }
             if (Input.GetKeyDown(dropKey))
             {
                 if (hitInfo.collider.tag == "WeaponManager")
                 {
                     WeaponDrop weaponDrop = hitInfo.collider.GetComponent<WeaponDrop>();
                     weaponDrop.Interact();
                 }
             }
 
 
             else
             {
                 interactText.enabled = false;
             }
 
 
 
 
         }
         
     }
 }
 


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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Photon Weapon View 1 Answer

How do you write a script for swinging a sword or just any weapon? 1 Answer

need help with a sway and recoil script for a weapon. 0 Answers

How can you do borderlands style random weapons and stat generation? 2 Answers

Pick up Weapons 1 Answer

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