Question by
SirOrange · Feb 21, 2017 at 09:41 PM ·
raycastdestroyfps controller
Raycast Destroying Whole fpscontroller? New to coding...
When I want to pickup items with this script, but it destroys the whole fps character instead? Why? Help ASAP! using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Pickp : MonoBehaviour {
public GameObject Axe;
public GameObject Axepl;
public Transform Drop;
public Animator Chop;
public int Equip;
public GameObject pistolpl;
public GameObject Pistol;
private Inventory inventory;
public Transform Crosshair;
public float weaponRange = 3.5f;
public Camera FPSCamera;
void Start () {
Equip = 0;
Chop = GetComponent<Animator> ();
Axepl.SetActive (false);
pistolpl.SetActive (false);
}
void Update () {
Ray ray = FPSCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
RaycastHit hitInfo;
if(Input.GetMouseButtonDown(1) && Equip == 1){
Equip = 0;
Instantiate (Axe, Drop.position, Drop.rotation);
Axepl.SetActive (false);
}
if(Input.GetMouseButtonDown(1) && Equip == 2){
Equip = 0;
Instantiate (Pistol, Drop.position, Drop.rotation);
pistolpl.SetActive (false);
}
if (Input.GetKeyDown(KeyCode.E)) {
if (Physics.Raycast (ray, out hitInfo, weaponRange)) {
if (hitInfo.collider.tag == "Axe") {
Axepl.SetActive (true);
Equip = 1;
Destroy (gameObject);
}
if (hitInfo.collider.tag == "Pistol") {
pistolpl.SetActive (true);
Equip = 2;
Destroy (gameObject);
}
if (hitInfo.collider.tag == "Wood") {
Inventory.Wood++;
Destroy (gameObject);
}
}
}
}
}
Comment