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
Your answer
Follow this Question
Related Questions
Photon Weapon View 1 Answer
How do you write a script for swinging a sword or just any weapon? 1 Answer
drag and merge object 0 Answers
need help with a sway and recoil script for a weapon. 0 Answers
How can i sort a List ? 1 Answer