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

Student.cs 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Grpc.Core;
  5. using Google.Protobuf;
  6. using Protobuf;
  7. using System.Data;
  8. public class Student : MonoBehaviour
  9. {
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. num = studentCount;
  14. studentCount++;
  15. anim = GetComponent<Animator>();
  16. occupation = MessageReceiver.Student[num].StudentType;
  17. transform.position = lastPosition = new Vector3(MessageReceiver.Student[num].Y / 1000.0f,
  18. 50.0f - MessageReceiver.Student[num].X / 1000.0f,
  19. 50.0f - MessageReceiver.Student[num].X / 1000.0f - 0.5f);
  20. }
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. var currentPosition = new Vector3(MessageReceiver.Student[num].Y / 1000.0f,
  25. 50.0f - MessageReceiver.Student[num].X / 1000.0f,
  26. 50.0f - MessageReceiver.Student[num].X / 1000.0f - 0.5f);
  27. Vector3 step = currentPosition - lastPosition;
  28. if (step != Vector3.zero)
  29. {
  30. transform.position = currentPosition;
  31. anim.SetBool("isRun", true);
  32. }
  33. else
  34. {
  35. anim.SetBool("isRun", false);
  36. }
  37. lastPosition = currentPosition;
  38. }
  39. private int num;
  40. private StudentType occupation;
  41. private Vector3 lastPosition = new Vector3(0, 0, 10.0f);
  42. private static int studentCount = 0;
  43. private Animator anim;
  44. }