You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RemotePlayer : Player {
  5. public Animator Animator;
  6. public GameObject PlayerModel;
  7. private float walkSpeed;
  8. private Vector3 lastPosition;
  9. private float LastSpeed = 0;
  10. protected override void Start()
  11. {
  12. base.Start();
  13. lastPosition = transform.position;
  14. }
  15. protected override void Update()
  16. {
  17. DoAnimation();
  18. base.Update();
  19. }
  20. private void DoAnimation()
  21. {
  22. Vector3 dir = transform.position - lastPosition;
  23. lastPosition = transform.position;
  24. float DesiredSpeed = dir.magnitude * 10;
  25. float setSpeed = Mathf.Lerp(LastSpeed, DesiredSpeed, 0.1f);
  26. Animator.SetFloat("WalkSpeed", setSpeed);
  27. //Debug.Log(setSpeed);
  28. LastSpeed = setSpeed;
  29. PlayerModel.transform.LookAt(PlayerModel.transform.position + dir, Vector3.up);
  30. //PlayerModel.transform.forward = dir.normalized;
  31. }
  32. public override void SetName(string Name)
  33. {
  34. TMPro.TextMeshPro textMesh = GetComponentInChildren<TMPro.TextMeshPro>();
  35. if (textMesh != null)
  36. textMesh.text = Name;
  37. }
  38. }