示例#1
0
        private void OnTriggerEnter2D(Collider2D other)
        {
            if (!other.gameObject.CompareTag("Sword"))
            {
                return;
            }

            string colName = gameObject.name;

            switch (colName)
            {
            case "Front":

                if (!backHit)
                {
                    frontHit = true;
                    _general.ReduceHealthByAmount(other.GetComponent <Init>().damage);
                }

                break;

            case "Back":
                if (!frontHit)
                {
                    backHit = true;
                    if (other.GetComponent <Init>().shield > 0)
                    {
                        other.GetComponent <Init>().shield--;
                    }
                    else
                    {
                        other.gameObject.GetComponent <Respawner>().respawn();
                        _master.ReduceLife(1);
                    }
                }

                break;

            default:
                Debug.Log("No collisions");
                break;
            }
        }
示例#2
0
        private void OnTriggerEnter2D(Collider2D other)
        {
            if (!other.gameObject.CompareTag("Sword"))
            {
                Debug.Log("No sword");
                return;
            }


            if (other.GetComponent <Init>().shield > 0)
            {
                other.GetComponent <Init>().shield--;
                Debug.Log("Shield Absorb");
            }
            else
            {
                Debug.Log("Direct hit");
                other.gameObject.GetComponent <Respawner>().respawn();
                _master.ReduceLife(1);
            }
        }