Esempio n. 1
0
    public override State Update()
    {
        IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI();
        IceSlime   iceSlime   = (IceSlime)iceSlimeAI.getCharacter();
        GameObject myBody     = iceSlime.GetGameObject();

        float distance = Vector3.Distance(myBody.transform.position, iceSlime.currentTarget.transform.position);

        //如果有目标在视野内,则移动向目标,直到可以攻击到目标
        if (distance < iceSlime.getAttr().getAttackRange())
        {
            myBody.GetComponent <Rigidbody2D>().velocity = Vector3.zero;
            return(State.SUCESSED);
        }

        Room1 room = (Room1)myBody.GetComponentInParent(typeof(Room1));
        float dx   = myBody.transform.position.x;
        float dy   = myBody.transform.position.y;

        if (dx >= room.transform.position.x + room.max_X || dx <= room.transform.position.x - room.max_X)
        {
            myBody.GetComponent <Rigidbody2D>().velocity = new Vector2(0, myBody.GetComponent <Rigidbody2D>().velocity.y);
        }
        if (dy >= room.transform.position.y + room.max_Y || dy <= room.transform.position.y - room.max_Y)
        {
            myBody.GetComponent <Rigidbody2D>().velocity = new Vector2(myBody.GetComponent <Rigidbody2D>().velocity.x, 0);
        }

        Vector3 dir = (iceSlime.currentTarget.transform.position - myBody.transform.position).normalized;

        myBody.GetComponent <Rigidbody2D>().velocity = dir * GetAI().getCharacter().getAttr().getSpeed() * Time.deltaTime;
        return(State.RUNNING);
    }
Esempio n. 2
0
    public override State Update()
    {
        IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI();
        IceSlime   iceSlime   = (IceSlime)iceSlimeAI.getCharacter();
        GameObject myBody     = iceSlime.GetGameObject();

        attackRange = iceSlime.getAttr().getAttackRange();
        if (Vector3.Distance(myBody.transform.position, iceSlime.currentTarget.transform.position) < attackRange)
        {
            return(State.SUCESSED);
        }
        return(State.FAILED);
    }
Esempio n. 3
0
    public override void Enter()
    {
        base.Enter();
        IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI();
        IceSlime   iceSlime   = (IceSlime)iceSlimeAI.getCharacter();

        if (childrenStates.Count == 0)
        {
            AddChild(iceSlimeAI.GetConditionHaveEnemy());
            iceSlimeAI.GetConditionHaveEnemy().currentState = State.NONE;
            AddChild(iceSlimeAI.GetDistanceCondition());
            iceSlimeAI.GetDistanceCondition().currentState = State.NONE;
            AddChild(iceSlimeAI.GetLaunchIce());
            iceSlimeAI.GetLaunchIce().currentState = State.NONE;
        }
    }
Esempio n. 4
0
    public override State Update()
    {
        IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI();
        IceSlime   iceSlime   = (IceSlime)iceSlimeAI.getCharacter();
        GameObject myBody     = iceSlime.GetGameObject();

        if (currentAttackRate < attackRate)
        {
            currentAttackRate += Time.deltaTime;
            currentState       = State.RUNNING;
        }
        else
        {
            if (!isFire)
            {
                if (currentDuring >= fireDuring)
                {
                    currentDuring = 0;
                    GameObject go  = Object.Instantiate(ice, myBody.transform.position, Quaternion.identity);
                    float      rad = Random.Range(-5, 5);
                    go.transform.localRotation *= Quaternion.Euler(0, 0, angle + rad);
                    go.GetComponent <Rigidbody2D>().velocity = go.transform.up * iceSpeed * Time.deltaTime;
                    count--;
                }
                currentDuring += Time.deltaTime;
                if (count <= 0)
                {
                    isFire = true;
                }
            }
            else
            {
                if (currentRecoverTime < recoverTime)
                {
                    currentRecoverTime += Time.deltaTime;
                }
                else
                {
                    return(State.SUCESSED);;
                }
            }
        }
        return(State.RUNNING);
    }
Esempio n. 5
0
    public override void Enter()
    {
        base.Enter();
        IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI();
        IceSlime   iceSlime   = (IceSlime)iceSlimeAI.getCharacter();
        GameObject myBody     = iceSlime.GetGameObject();

        ice                = iceSlime.GetIce();
        attackRate         = iceSlime.getAttr().getAttackRate();
        currentAttackRate  = 0;
        currentRecoverTime = 0;
        isFire             = false;
        currentDuring      = fireDuring;
        count              = 5;
        angle              = Vector3.Angle(myBody.transform.up, (iceSlime.currentTarget.transform.position - myBody.transform.position).normalized);
        Vector3 cro = Vector3.Cross(myBody.transform.up, (iceSlime.currentTarget.transform.position - myBody.transform.position).normalized);

        angle *= Vector3.Dot(cro.normalized, myBody.transform.forward);
    }
Esempio n. 6
0
    public override State Update()
    {
        IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI();
        IceSlime   iceSlime   = (IceSlime)iceSlimeAI.getCharacter();
        GameObject myBody     = iceSlime.GetGameObject();

        if (iceSlime.currentTarget != null)
        {
            return(State.SUCESSED);
        }

        iceSlime.targets = Physics2D.OverlapCircleAll(myBody.transform.position, eyeViewDistance, LayerMask.GetMask("Player"));
        Collider2D[] targets = iceSlime.targets;

        if (targets != null && targets.Length > 0)
        {
            iceSlime.currentTarget = targets[0];
            return(State.SUCESSED);
        }
        return(State.FAILED);
    }