SoccerDemo.cs 813 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace RootMotion.Demos {
  4. public class SoccerDemo : MonoBehaviour {
  5. private Animator animator;
  6. private Vector3 defaultPosition;
  7. private Quaternion defaultRotation;
  8. void Start () {
  9. animator = GetComponent<Animator>();
  10. // Remember the default position and rotation of the character
  11. defaultPosition = transform.position;
  12. defaultRotation = transform.rotation;
  13. StartCoroutine(ResetDelayed());
  14. }
  15. // Reset the character after some time and restart the animation
  16. private IEnumerator ResetDelayed() {
  17. while (true) {
  18. yield return new WaitForSeconds(3f);
  19. transform.position = defaultPosition;
  20. transform.rotation = defaultRotation;
  21. animator.CrossFade("SoccerKick", 0f, 0, 0f);
  22. yield return null;
  23. }
  24. }
  25. }
  26. }