aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/Boulder.cs
diff options
context:
space:
mode:
authorNeil Kollack <nkollack@gmail.com>2022-04-15 00:32:41 -0500
committerNeil Kollack <nkollack@gmail.com>2022-04-15 00:32:41 -0500
commit58d16dec85dbbb83c7ba503e735585f922bf67b9 (patch)
tree1203153d0395d009da8b2f866e1c231ca57be8ab /Assets/Scripts/Boulder.cs
parent929254005c7dc7437208715a6ae04b69292fe4f7 (diff)
feat: escape sequence
Diffstat (limited to 'Assets/Scripts/Boulder.cs')
-rw-r--r--Assets/Scripts/Boulder.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/Assets/Scripts/Boulder.cs b/Assets/Scripts/Boulder.cs
new file mode 100644
index 0000000..5aa2beb
--- /dev/null
+++ b/Assets/Scripts/Boulder.cs
@@ -0,0 +1,45 @@
+using MontanaJohns.Actors;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Boulder : MonoBehaviour
+{
+ [SerializeField] float speed;
+ [SerializeField] float maxSpeed;
+
+ private GameObject player;
+ private Rigidbody2D rb;
+
+ // Start is called before the first frame update
+ void Start()
+ {
+ player = GameObject.FindGameObjectWithTag("Player");
+ rb = transform.GetComponent<Rigidbody2D>();
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+ if (player.transform.position.x < transform.position.x)
+ {
+ transform.Rotate(0, 0, 1);
+ }
+ else
+ {
+ transform.Rotate(0, 0, -1);
+ }
+ transform.position = Vector2.MoveTowards(transform.position, new Vector2(player.transform.position.x, 0), speed * Time.deltaTime);
+ if(rb.velocity.x >= maxSpeed)
+ rb.velocity = new Vector2(maxSpeed, rb.velocity.y);
+ }
+
+ private void OnTriggerEnter2D(Collider2D collision)
+ {
+ if (collision.gameObject.tag == "Player")
+ {
+ collision.GetComponent<Actor>().TakeDamage(999);
+ }
+ }
+}