コード例 #1
0
    /// <summary>
    /// 判断是否攻击到了怪物
    /// </summary>
    /// <param name="hurt"></param>
    void AttackMonster(float hurt)
    {
        for (int i = 0; i < MonsterManager.sMonsterManager.MonsterLst.Count; i++)
        {
            GameObject       monster = MonsterManager.sMonsterManager.MonsterLst[i];
            DragonController ctr     = monster.GetComponent <DragonController>();
            if (ctr.IsDeath())
            {
                continue;
            }

            Vector3 dir = monster.transform.position - transform.position;
            if (dir.magnitude > mAttackLen)
            {
                continue;
            }

            float cos = Vector3.Dot(dir.normalized, transform.forward);
            if (cos <= 0.2f)
            {
                continue;
            }

            ctr.GetHit(hurt);
        }
    }