diff options
Diffstat (limited to 'GameCode/FollowRandomPlayer.cs')
-rw-r--r-- | GameCode/FollowRandomPlayer.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/GameCode/FollowRandomPlayer.cs b/GameCode/FollowRandomPlayer.cs new file mode 100644 index 0000000..c8d8516 --- /dev/null +++ b/GameCode/FollowRandomPlayer.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +public class FollowRandomPlayer : MonoBehaviour +{ + public bool X = true; + + public bool Y = true; + + private Transform targetPlayer; + + public bool snap; + + private void Start() + { + } + + private void Update() + { + if (!targetPlayer) + { + GetNewPlayer(); + } + else if (snap) + { + base.transform.position = new Vector3(X ? targetPlayer.position.x : base.transform.position.x, Y ? targetPlayer.position.y : base.transform.position.y, 0f); + } + else + { + base.transform.position = Vector3.Lerp(base.transform.position, new Vector3(X ? targetPlayer.position.x : base.transform.position.x, Y ? targetPlayer.position.y : base.transform.position.y, 0f), TimeHandler.deltaTime * 5f); + } + } + + private void GetNewPlayer() + { + if (PlayerManager.instance.players.Count > 0) + { + targetPlayer = PlayerManager.instance.players[Random.Range(0, PlayerManager.instance.players.Count)].transform; + } + } +} |