-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAIMovement.cs
43 lines (39 loc) · 995 Bytes
/
AIMovement.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 AIMovement : MonoBehaviour
{
public Transform player;
public float speed = 2;
public Vector3 target;
public bool shrink;
void Start()
{
GetNewTarget();
shrink = false;
}
void Update()
{
if (Vector3.Distance(transform.position, target) < 1)
{
GetNewTarget();
}
transform.position = Vector3.Lerp(transform.position, target, Time.deltaTime * speed);
if (shrink)
{
Shrink();
}
}
public void GetNewTarget()
{
target = new Vector3(Random.Range(-5, 5), 1f, Random.Range(-5, 5));
}
public void Shrink()
{
if(Vector3.Magnitude(transform.localScale) < .1)
{
Destroy(gameObject);
}
transform.localScale -= new Vector3(.001f, .001f, .001f);
}
}