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/CharacterItemMirror.cs |
+ init
Diffstat (limited to 'GameCode/CharacterItemMirror.cs')
-rw-r--r-- | GameCode/CharacterItemMirror.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/GameCode/CharacterItemMirror.cs b/GameCode/CharacterItemMirror.cs new file mode 100644 index 0000000..d3ff572 --- /dev/null +++ b/GameCode/CharacterItemMirror.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +public class CharacterItemMirror : MonoBehaviour +{ + private float speedThreshol = 3f; + + private LeftRight leftRight; + + private Player player; + + private void Start() + { + player = GetComponentInParent<Player>(); + if (base.transform.localPosition.x > 0f) + { + leftRight = LeftRight.Right; + } + else + { + leftRight = LeftRight.Left; + } + } + + private void Update() + { + LeftRight leftRight = this.leftRight; + if (player.data.playerVel.velocity.x > speedThreshol) + { + leftRight = LeftRight.Right; + } + if (player.data.playerVel.velocity.x < 0f - speedThreshol) + { + leftRight = LeftRight.Left; + } + if (leftRight != this.leftRight) + { + base.transform.localPosition = new Vector3(base.transform.localPosition.x * -1f, base.transform.localPosition.y, base.transform.localPosition.z); + base.transform.localScale = new Vector3(base.transform.localScale.x * -1f, base.transform.localScale.y, base.transform.localScale.z); + this.leftRight = leftRight; + } + } +} |