diff options
author | chai <215380520@qq.com> | 2024-05-20 20:28:49 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-20 20:28:49 +0800 |
commit | db64ca2ebcfc2239702ba53e3497b44cd14d8c27 (patch) | |
tree | be17abde084302284e5acc69bed0c2dfd83f9cf7 /Valheim_v202102/Valheim/assembly_valheim/FollowPlayer.cs |
+init
Diffstat (limited to 'Valheim_v202102/Valheim/assembly_valheim/FollowPlayer.cs')
-rw-r--r-- | Valheim_v202102/Valheim/assembly_valheim/FollowPlayer.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Valheim_v202102/Valheim/assembly_valheim/FollowPlayer.cs b/Valheim_v202102/Valheim/assembly_valheim/FollowPlayer.cs new file mode 100644 index 0000000..d5c2992 --- /dev/null +++ b/Valheim_v202102/Valheim/assembly_valheim/FollowPlayer.cs @@ -0,0 +1,37 @@ +using UnityEngine; + +public class FollowPlayer : MonoBehaviour +{ + public enum Type + { + Player, + Camera + } + + public Type m_follow = Type.Camera; + + public bool m_lockYPos; + + public bool m_followCameraInFreefly; + + public float m_maxYPos = 1000000f; + + private void LateUpdate() + { + Camera mainCamera = Utils.GetMainCamera(); + if (!(Player.m_localPlayer == null) && !(mainCamera == null)) + { + Vector3 zero = Vector3.zero; + zero = ((m_follow != Type.Camera && !GameCamera.InFreeFly()) ? Player.m_localPlayer.transform.position : mainCamera.transform.position); + if (m_lockYPos) + { + zero.y = base.transform.position.y; + } + if (zero.y > m_maxYPos) + { + zero.y = m_maxYPos; + } + base.transform.position = zero; + } + } +} |