Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        //Attack
        if (Input.GetMouseButtonDown(0) && equipped != null && equipped.GetComponent <MeleeWeapon>() != null)
        {
            MeleeWeapon w = equipped.GetComponent <MeleeWeapon>();


            w.activate();

            //if (!w.isActive) { w.activate(); }
        }

        //Unequip
        if (Input.GetMouseButtonDown(1) && equipped != null)
        {
            equipped.transform.parent = null;
            GrabableObject go = equipped.GetComponent <GrabableObject>();
            go.owner = null;
            go.reset_y_position();
            equipped.transform.localRotation = Quaternion.identity;
            equipped = null;
            anim.SetBool("isHolding", false);

            //play sound
            TempSoundPlayer sp = (Instantiate(Resources.Load("TempSoundPlayer"), transform.position, transform.rotation) as GameObject).GetComponent <TempSoundPlayer>();
            sp.setVolume(0.2f);
            sp.playSound(drop_sound);
        }
    }
Beispiel #2
0
    private void OnTriggerStay(Collider other)
    {
        if (Input.GetKeyDown(KeyCode.E) && other.GetComponent <GrabableObject>() != null && equipped == null)
        {
            equipped = other.gameObject;
            equipped.transform.parent = grabPoint.transform;
            GrabableObject go = other.gameObject.GetComponent <GrabableObject>();
            equipped.transform.localPosition = go.position_offset;
            equipped.transform.localRotation = go.rotation_offset;
            go.owner = this.gameObject;
            //equipped.GetComponent<CapsuleCollider>().enabled = false;
            if (go.two_hand_hold)
            {
                anim.SetBool("isHolding", true);
            }

            //play sound
            TempSoundPlayer sp = (Instantiate(Resources.Load("TempSoundPlayer"), transform.position, transform.rotation) as GameObject).GetComponent <TempSoundPlayer>();
            sp.setVolume(0.2f);
            sp.playSound(pickup_sound);
        }
    }