diff options
Diffstat (limited to 'GameCode/FollowPlayer.cs')
-rw-r--r-- | GameCode/FollowPlayer.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/GameCode/FollowPlayer.cs b/GameCode/FollowPlayer.cs new file mode 100644 index 0000000..cd3c826 --- /dev/null +++ b/GameCode/FollowPlayer.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +public class FollowPlayer : MonoBehaviour +{ + public enum Target + { + Self, + Other + } + + public Target target; + + public bool inheritScale = true; + + private Vector3 startScale; + + private Player ownPlayer; + + private void Start() + { + startScale = base.transform.localScale; + ownPlayer = GetComponentInParent<Player>(); + if (!ownPlayer) + { + ownPlayer = GetComponentInParent<SpawnedAttack>().spawner; + } + } + + private void LateUpdate() + { + Player player = null; + player = ((target != Target.Other) ? ownPlayer : PlayerManager.instance.GetOtherPlayer(ownPlayer)); + if (inheritScale) + { + base.transform.localScale = new Vector3(player.transform.localScale.x * startScale.x, player.transform.localScale.y * startScale.y, player.transform.localScale.z * startScale.z); + } + base.transform.position = player.transform.position; + base.transform.rotation = player.transform.rotation; + } +} |