aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2019-04-27 15:23:18 +0200
committermarcinzelent <zelent.marcin@gmail.com>2019-04-27 15:23:18 +0200
commit7539e35ce26437c5aa0325936dea68132408c8b0 (patch)
treebd676584a4af715b3b62ac2eab6d8b5dae0919cf /nGJ2019/Assets/Scripts/RockJaws.cs
parent0cfee1d1f1a2a06c86080f62ce26a3eabe6b5ffd (diff)
Added rock jaws obstacle
Diffstat (limited to 'nGJ2019/Assets/Scripts/RockJaws.cs')
-rw-r--r--nGJ2019/Assets/Scripts/RockJaws.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/nGJ2019/Assets/Scripts/RockJaws.cs b/nGJ2019/Assets/Scripts/RockJaws.cs
new file mode 100644
index 0000000..a161dfe
--- /dev/null
+++ b/nGJ2019/Assets/Scripts/RockJaws.cs
@@ -0,0 +1,37 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class RockJaws : MonoBehaviour
+{
+ public Transform TopJaw;
+ public Transform BottomJaw;
+ public int Speed = 10;
+ private bool reverse = false;
+ private float initialTopJawY;
+ // Start is called before the first frame update
+ void Start()
+ {
+ initialTopJawY = TopJaw.localPosition.y;
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+
+ void FixedUpdate()
+ {
+ if (TopJaw.localPosition.y < BottomJaw.localPosition.y) reverse = true;
+ else if(TopJaw.localPosition.y > initialTopJawY) reverse = false;
+
+ if (!reverse) {
+ TopJaw.Translate(0, -0.01f * Speed, 0);
+ BottomJaw.Translate(0, 0.01f * Speed, 0);
+ } else {
+ TopJaw.Translate(0, 0.01f * Speed, 0);
+ BottomJaw.Translate(0, -0.01f * Speed, 0);
+ }
+ }
+}