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.

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