-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cs
More file actions
30 lines (25 loc) · 794 Bytes
/
Enemy.cs
File metadata and controls
30 lines (25 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
private float direction = 1;
public float velocity = 5f;
private GrabController grabController;
private void Start() {
grabController = FindObjectOfType<GrabController>();
}
// Update is called once per frame
void Update()
{
this.transform.Translate(Vector2.right * direction * velocity * Time.deltaTime);
if(transform.position.x > 4.5f || transform.position.x < -4.5f) {
this.direction *= -1;
}
}
private void OnTriggerEnter2D(Collider2D collision) {
if(collision.gameObject.tag == "Player") {
grabController.Drop();
}
}
}