Esempio n. 1
0
    private void OnTriggerStay(Collider other)
    {
        if (other.tag == enemyTagName)
        {
            enemyWeapon = other.gameObject.GetComponentInChildren <EnemyWeapon>();

            if (Input.GetKeyUp(fireBtn))
            {
                timer = 0;
                if (enemyWeapon)
                {
                    enemyWeapon.returnToOrigin();
                }
            }

            if (Input.GetKey(fireBtn))
            {
                if (timer < holdTime)
                {
                    timer += Time.deltaTime;
                    if (enemyWeapon)
                    {
                        enemyWeapon.weaponPulled = true;
                        var pullDirection = this.transform.position - enemyWeapon.gameObject.transform.position;
                        enemyWeapon.gameObject.GetComponent <Rigidbody>().position += pullDirection.normalized * 0.1f;
                    }
                }
                else if (timer >= holdTime)
                {
                    if (enemyWeapon)
                    {
                        enemy = other.gameObject.GetComponentInParent <Enemy>();
                        enemy.onTransform();
                        Destroy(enemyWeapon.gameObject);
                    }
                }
            }
        }
    }