Exemplo n.º 1
0
 public void SetFrightened()
 {
     if (!(state is DeadState || state is GoingHomeState))
     {
         SoundManager.instance.PlaySingle(frightned, 3);
         state.Exit(this);
         state = new FrightnedState(this);
         state.Start(this);
     }
 }
Exemplo n.º 2
0
        void FixedUpdate()
        {
            var nextState = state.Update(this);

            if (nextState != null)
            {
                state.Exit(this);
                state = nextState;
                state.Start(this);
            }

            direction = Vector2Int.FloorToInt((target - body.position).normalized);
            if (state is FrightnedState)
            {
                animator.SetTrigger("frightned");
            }
            else if (state is GoingHomeState)
            {
                if (direction == Vector2Int.right)
                {
                    animator.SetTrigger("deadright");
                }
                else if (direction == Vector2Int.down)
                {
                    animator.SetTrigger("deaddown");
                }
                else if (direction == Vector2Int.up)
                {
                    animator.SetTrigger("deadup");
                }
                else
                {
                    animator.SetTrigger("deadleft");
                }
            }
            else
            {
                if (direction == Vector2Int.right)
                {
                    animator.SetTrigger("right");
                }
                else if (direction == Vector2Int.down)
                {
                    animator.SetTrigger("down");
                }
                else if (direction == Vector2Int.up)
                {
                    animator.SetTrigger("up");
                }
                else
                {
                    animator.SetTrigger("left");
                }
            }
        }
Exemplo n.º 3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("Player"))
     {
         if (state is FrightnedState)
         {
             GameManager.instance.AddScore(200);
             GameManager.instance.PauseGame(0.5f);
             SoundManager.instance.PlaySingle(eatGhost, 2);
             state.Exit(this);
             state = new GoingHomeState(this);
             state.Start(this);
         }
         else if (!(state is GoingHomeState))
         {
             SoundManager.instance.PlaySingle(playerDead, 2);
             GameManager.instance.PauseGame(10f);
             GameManager.instance.GameOver();
             SoundManager.instance.StopMusic();
             player.Die();
         }
     }
 }