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.

83 lines
2.3 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. private void Start()
  12. {
  13. localPlayer = Multiplayer.PlayersManager.Instance.LocalPlayer;
  14. Players.Add(localPlayer);
  15. foreach (GameObject curPlayer in Multiplayer.PlayersManager.Instance.RemotePlayers.Values)
  16. {
  17. Players.Add(curPlayer);
  18. }
  19. cam = localPlayer.GetComponentInChildren<Camera>();
  20. }
  21. //Public movement functions :)
  22. private void Update()
  23. {
  24. if (Input.GetMouseButton(0))
  25. {
  26. Vector3 mousePos = new Vector3(Input.mousePosition.x, 0.0f, Input.mousePosition.y);
  27. Vector3 screenCentre = new Vector3(Screen.width / 2, 0.0F, Screen.height / 2);
  28. Vector3 movePos = mousePos - screenCentre;
  29. movePos.x = movePos.x / Screen.width;
  30. movePos.z = movePos.z / Screen.height;
  31. localPlayer.GetComponent<CharacterController>().Move(movePos * Speed * Time.deltaTime);
  32. Debug.Log("Movepos" + movePos + " speed " + Speed);
  33. }
  34. }
  35. public bool CheckNearby()
  36. {
  37. for (int i = 0; i < Players.Count; i++)
  38. {
  39. if ((localPlayer.transform.position - Players[i].transform.position).magnitude < DistanceToWin)
  40. {
  41. Greet();
  42. }
  43. else
  44. {
  45. Player playerScript = Players[i].GetComponent<Player>();
  46. foreach (GameObject dummy in playerScript.dummies)
  47. {
  48. if ((localPlayer.transform.position - dummy.transform.position).magnitude < DistanceToWin)
  49. {
  50. Greet();
  51. }
  52. }
  53. }
  54. }
  55. return CheckWin();
  56. }
  57. bool CheckWin()
  58. {
  59. for (int i = 0; i < Nearby.Count; i++)
  60. {
  61. if (Nearby[i] == false)
  62. {
  63. return false;
  64. }
  65. }
  66. return true;
  67. }
  68. public void Greet()
  69. {
  70. //Play audio
  71. //Trigger animation
  72. }
  73. }