示例#1
0
    public void RunAI()
    {
        CharacterInfo targetInfo = soliderInfo.RunAI();

        //若未找到目标,继续空闲
        if (targetInfo == null)
        {
            soliderInfo.ChangeState("idle");
        }
        //若找到目标,目标停住,并进入移动状态
        else
        {
            //双方都输入攻击目标,均被占用,不再接受其他人的约战
            targetInfo.SetAttackInfo(soliderInfo);
            targetInfo.ChangeState("idle", soliderInfo);
            soliderInfo.SetAttackInfo(targetInfo);
            soliderInfo.ChangeState("move", targetInfo);
        }
    }
示例#2
0
    public void Excute()
    {
        Vector3 pos = soliderInfo.GetPosition();
        float   dis = Vector3.Distance(pos, targetPos);

        if (dis < speed * Time.deltaTime)
        {
            soliderInfo.SetPosition(targetPos.x, targetPos.y, targetPos.z);
            CharacterInfo attackInfo = soliderInfo.GetAttackInfo();
            soliderInfo.SetAttackInfo(attackInfo);
            attackInfo.SetAttackInfo(soliderInfo);
            soliderInfo.ChangeState("attack", attackInfo);
            attackInfo.ChangeState("attack", soliderInfo);
        }
        else
        {
            pos = Vector3.MoveTowards(pos, targetPos, Time.deltaTime * speed);
            soliderInfo.SetPosition(pos.x, pos.y, pos.z);
        }
    }