diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/FollowPlayer.cs |
+ init
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; + } +} |