Ejemplo n.º 1
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         gun_logic gun = other.GetComponentInChildren <gun_logic>();
         if (gun)
         {
             gun.refill_ammo();
             Destroy(gameObject);
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        m_horizontalaxis = Input.GetAxis("Horizontal");
        m_verticalaxis   = Input.GetAxis("Vertical");
        total_move       = new Vector3(-m_verticalaxis, 0, m_horizontalaxis);

        if (Input.GetButtonDown("Jump") && !isjumping)
        {
            isjumping = true;
        }
        if (m_interactableobject && Input.GetButtonDown("Fire2"))
        {
            if (!m_equppedobject)
            {
                gun_logic gun = m_interactableobject.GetComponent <gun_logic>();
                if (gun)
                {
                    //sets the position of the gun
                    m_interactableobject.transform.rotation = equipposition.rotation;
                    m_interactableobject.transform.position = equipposition.position;
                    m_interactableobject.transform.parent   = gameObject.transform;
                    m_equppedobject = m_interactableobject;

                    //deactivate gravity and deactivate collider
                    gun.equip_weapon();
                }
            }
            else if (m_equppedobject == m_interactableobject)
            {
                gun_logic gun = m_interactableobject.GetComponent <gun_logic>();
                if (gun)
                {
                    //sets the position of the gun
                    m_interactableobject.transform.parent = null;
                    m_equppedobject = null;
                    //activate gravity and activate collider
                    gun.unequip_weapon();
                }
            }
            else if (m_equppedobject != m_interactableobject)
            {
                gun_logic gun = m_equppedobject.GetComponent <gun_logic>();
                if (gun)
                {
                    //sets the position of the gun
                    m_equppedobject.transform.parent = null;
                    m_equppedobject = null;
                    //activate gravity and activate collider
                    gun.unequip_weapon();
                }
                gun_logic gunn = m_interactableobject.GetComponent <gun_logic>();
                if (gunn)
                {
                    //sets the position of the gun
                    m_interactableobject.transform.rotation = equipposition.rotation;
                    m_interactableobject.transform.position = equipposition.position;
                    m_interactableobject.transform.parent   = gameObject.transform;
                    m_equppedobject = m_interactableobject;
                    gunn.refill_ammo();
                    //deactivate gravity and deactivate collider
                    gunn.equip_weapon();
                }
            }
        }
    }