summaryrefslogtreecommitdiff
path: root/GameCode/CharacterItemMirror.cs
diff options
context:
space:
mode:
Diffstat (limited to 'GameCode/CharacterItemMirror.cs')
-rw-r--r--GameCode/CharacterItemMirror.cs42
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;
+ }
+ }
+}