// Update is called once per frame
    void Update()
    {
        switch (_FriendlyCurrentState)
        {
        case Friendlystate.Idle:
            if (_timeridle < 0)
            {
                //idle
                _FriendlyAnimation.PlayIdle();
                _timeridle = timeridle;
            }
            else
            {
                _timeridle -= Time.deltaTime;
            }
            break;

        case Friendlystate.Walking:
            if (_timerwalking < 0)
            {
                //walking
                _FriendlyAnimation.PlayWalking();
                _timerwalking = timerwalking;
            }
            else
            {
                _timerwalking -= Time.deltaTime;
            }
            break;

        case Friendlystate.Atacking:

            break;

        case Friendlystate.Hit:

            break;

        case Friendlystate.Jumping:

            break;
        }

        targetx = GameObject.Find("Player").transform.position.x;
        x       = transform.position.x;

        if (x >= targetx - 3f || x <= targetx - 4f)        //link
        {
            _FriendlyCurrentState = Friendlystate.Walking;
        }
        else
        {
            _FriendlyCurrentState = Friendlystate.Idle;
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        x = gameObject.transform.position.x;
        y = gameObject.transform.position.y;

        targetx = player.transform.position.x;
        targety = player.transform.position.y;

        switch (_EnemyCurrentState)
        {
        case Enemystate.Idle:
            if (_timeridle < 0)
            {
                //idle
                _EnemyAnimation.PlayIdle();
                _timeridle = timeridle;
            }
            else
            {
                _timeridle -= Time.deltaTime;
            }
            break;

        case Enemystate.Walking:
            if (_timerwalking < 0)
            {
                //walking
                _EnemyAnimation.PlayWalking();
                _timerwalking = timerwalking;
            }
            else
            {
                _timerwalking -= Time.deltaTime;
            }
            break;

        case Enemystate.Atacking:

            break;

        case Enemystate.Hit:

            break;

        case Enemystate.Jumping:
            if (_timerjumping < 0)
            {
                _EnemyAnimation.PlayJump();
                _timerjumping = timerjumping;
            }
            else
            {
                _timerjumping -= Time.deltaTime;
            }
            break;
        }



        if (flip)
        {
            gameObject.transform.rotation = Quaternion.Euler(0, 180, 0);
        }
        else if (!flip)
        {
            gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
        }

        if (x >= targetx + 0.5f && targetx >= x + lookingfield * -1)        //link
        {
            _EnemyCurrentState = Enemystate.Walking;
            flip = false;
            //print("hallo");
        }
        else if (x <= targetx - 0.5f && targetx <= x + lookingfield)        //rechts
        {
            //print("hallo 2");
            _EnemyCurrentState = Enemystate.Walking;
            flip = true;
        }
        else
        {
            _EnemyCurrentState = Enemystate.Idle;
        }

        if (y < targetx)
        {
            //_EnemyCurrentState = Enemystate.Jumping;
        }



        //print(flip);
    }