// Use this for initialization void Start() { m_controller = GetComponent <CharacterController>(); m_blender = GetComponent <MonsterColorBlend>(); m_animator = GetComponent <Animator>(); m_state = CreeperState.Alive; }
// Update is called once per frame void Update() { if (yukari != null) { if (m_controller.isGrounded) { if (m_state == CreeperState.Alive) { Vector3 yukariPos = yukari.transform.position; Vector3 direction = (yukariPos - transform.position).normalized; moveDirection = transform.forward = new Vector3(direction.x, 0, direction.z); moveDirection *= speed; } else if (m_state == CreeperState.Dead) { moveDirection.x = 0; moveDirection.z = 0; } if (m_knockBack) { moveDirection *= -0.5f; moveDirection.y = jumpSpeed; m_knockBack = false; } } } // Say I'm dead! if (m_state == CreeperState.Dead) { m_destroyTimer += Time.deltaTime; if (m_destroyTimer > 1f) { Spawner.Instance.MessageDead(this.gameObject); } } // Control hit animation if (m_hitAnimationTimer < 0.5f) { m_hitAnimationTimer += Time.deltaTime; m_animator.speed = 5f; } else if (m_hitAnimationTimer >= 0.5f) { m_hitAnimationTimer = 0.5f; m_animator.speed = 1f; } // Check whether it is dead if (health <= 0) { m_hitAnimationTimer = 0.5f; m_animator.speed = 1f; m_animator.SetBool("Dead", true); m_state = CreeperState.Dead; } // This code must be in bottom moveDirection.y -= gravity * Time.deltaTime; m_controller.Move(moveDirection * Time.deltaTime); }