-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyPathing.cs
43 lines (40 loc) · 939 Bytes
/
EnemyPathing.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyPathing : MonoBehaviour
{
public float speed;
public bool MoveRight;
private void Update()
{
if (speed == 0)
{
speed = .2f;
}
// if true, moves to right
if (MoveRight)
{
transform.Translate(2 * Time.deltaTime * speed, 0, 0);
transform.localScale = new Vector3(5f, 5f, 0);
}
else
{
transform.Translate(-2 * Time.deltaTime * speed, 0, 0);
transform.localScale = new Vector3(-5f, 5f, 0);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "turn")
{
if(MoveRight)
{
MoveRight = false;
}
else
{
MoveRight = true;
}
}
}
}