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.

80 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CharacterMovement : MonoBehaviour
  5. {
  6. public float Speed;
  7. GameObject localPlayer;
  8. public List<GameObject> Players = new List<GameObject>();
  9. List<bool> Nearby = new List<bool>();
  10. public float DistanceToWin;
  11. Camera cam;
  12. public AudioSource Cheer;
  13. private void Start()
  14. {
  15. localPlayer = Multiplayer.PlayersManager.Instance.LocalPlayer.gameObject;
  16. Players.Add(localPlayer);
  17. Nearby.Add(false);
  18. foreach (PlayerData curPlayer in Multiplayer.PlayersManager.Instance.Players.Values)
  19. {
  20. Players.Add(curPlayer.gameObject);
  21. Nearby.Add(false);
  22. }
  23. cam = localPlayer.GetComponentInChildren<Camera>();
  24. }
  25. public bool CheckNearby()
  26. {
  27. for (int i = 0; i < Players.Count; i++)
  28. {
  29. bool found = false;
  30. if ((localPlayer.transform.position - Players[i].transform.position).magnitude < DistanceToWin)
  31. {
  32. Greet();
  33. found = true;
  34. }
  35. else
  36. {
  37. Player playerScript = Players[i].GetComponent<Player>();
  38. foreach (GameObject dummy in playerScript.dummies)
  39. {
  40. if ((localPlayer.transform.position - dummy.transform.position).magnitude < DistanceToWin)
  41. {
  42. Greet();
  43. found = true;
  44. }
  45. }
  46. }
  47. Nearby[i] = found;
  48. }
  49. return CheckWin();
  50. }
  51. bool CheckWin()
  52. {
  53. for (int i = 0; i < Nearby.Count; i++)
  54. {
  55. if (Nearby[i] == false)
  56. {
  57. return false;
  58. }
  59. }
  60. return true;
  61. }
  62. public void Greet()
  63. {
  64. if (Cheer != null)
  65. {
  66. Cheer.Play();
  67. }
  68. //Trigger animation
  69. }
  70. }