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.

79 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
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. 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. Nearby.Add(false);
  17. foreach (GameObject curPlayer in Multiplayer.PlayersManager.Instance.RemotePlayers.Values)
  18. {
  19. Players.Add(curPlayer);
  20. Nearby.Add(false);
  21. }
  22. cam = localPlayer.GetComponentInChildren<Camera>();
  23. }
  24. public bool CheckNearby()
  25. {
  26. for (int i = 0; i < Players.Count; i++)
  27. {
  28. bool found = false;
  29. if ((localPlayer.transform.position - Players[i].transform.position).magnitude < DistanceToWin)
  30. {
  31. Greet();
  32. found = true;
  33. }
  34. else
  35. {
  36. Player playerScript = Players[i].GetComponent<Player>();
  37. foreach (GameObject dummy in playerScript.dummies)
  38. {
  39. if ((localPlayer.transform.position - dummy.transform.position).magnitude < DistanceToWin)
  40. {
  41. Greet();
  42. found = true;
  43. }
  44. }
  45. }
  46. Nearby[i] = found;
  47. }
  48. return CheckWin();
  49. }
  50. bool CheckWin()
  51. {
  52. for (int i = 0; i < Nearby.Count; i++)
  53. {
  54. if (Nearby[i] == false)
  55. {
  56. return false;
  57. }
  58. }
  59. return true;
  60. }
  61. public void Greet()
  62. {
  63. if (Cheer != null)
  64. {
  65. Cheer.Play();
  66. }
  67. //Trigger animation
  68. }
  69. }