Esempio n. 1
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);
    }