ActiveAnim.cs 772 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using UnityEngine;
  3. public class ActiveAnim : BaseBehaviour
  4. {
  5. private void Start()
  6. {
  7. this.player_x = R.Player.Transform.position.x;
  8. }
  9. private void Update()
  10. {
  11. this.player_x = R.Player.Transform.position.x;
  12. if (Mathf.Abs(this.player_x - base.transform.position.x) < this.distance)
  13. {
  14. base.gameObject.GetComponent<Animator>().enabled = true;
  15. base.gameObject.GetComponent<Animator>().Play(this.anim1);
  16. }
  17. if (Mathf.Abs(this.player_x - base.transform.position.x) >= this.distance)
  18. {
  19. base.gameObject.GetComponent<Animator>().enabled = false;
  20. }
  21. }
  22. private float player_x;
  23. [SerializeField]
  24. public float distance;
  25. [SerializeField]
  26. public string anim1;
  27. [SerializeField]
  28. public string anim2;
  29. }