ScriptAnimations.cs 1003 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. namespace Mirror.Examples.CharacterSelection
  3. {
  4. // A fun little bob script for characters.
  5. // You could reference this and change values depending on characters state, idle, walk, run.
  6. public class ScriptAnimations : MonoBehaviour
  7. {
  8. public float minimum = 0.1f;
  9. public float maximum = 0.5f;
  10. private float yPos;
  11. public float bounceSpeed = 3;
  12. private float yStartPosition;
  13. private void Start()
  14. {
  15. yStartPosition = this.transform.localPosition.y;
  16. }
  17. void Update()
  18. {
  19. float sinValue = Mathf.Sin(Time.time * bounceSpeed);
  20. yPos = Mathf.Lerp(maximum, minimum, Mathf.Abs((1.0f + sinValue) / 2.0f));
  21. transform.localPosition = new Vector3(transform.localPosition.x, yStartPosition + yPos, transform.localPosition.z);
  22. }
  23. }
  24. //credits https://stackoverflow.com/questions/67322860/how-do-i-make-a-simple-idle-bobbing-motion-animation
  25. }