コード例 #1
0
ファイル: Unit.cs プロジェクト: JMOatey/CapstoneProject
    void Attack()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Ray    ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
            string team = TurnManager.Instance.CurrentUnit.tag;

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Unit unit = hit.collider.GetComponent <Unit>();
                if (AttackableTiles.Contains(unit.CurrentTile) && ((hit.collider.tag == "Player" && team == "Enemy") || (hit.collider.tag == "Enemy" && team == "Player")))
                {
                    //Play Attack Animation
                    Transform model = transform.Find("Player Model");
                    Animator  anim  = model.GetComponent <Animator>();
                    anim.Play("attack", -1);

                    //Attack Logic
                    Debug.Log(unit);
                    Debug.Log(unit.Health);
                    if (unit.Health > 0)
                    {
                        //onHit Animation
                        Animator hitAnimation = hit.collider.GetComponentInChildren <Animator>();
                        hitAnimation.Play("onHit", -1);

                        unit.Health -= AttackDamage;
                        if (unit.Health < 0)
                        {
                            unit.Health = 0;
                        }
                    }
                    HasAttacked = true;
                }
            }
        }
    }