-
Notifications
You must be signed in to change notification settings - Fork 0
/
AI_follow.cs
37 lines (32 loc) · 898 Bytes
/
AI_follow.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
using UnityEngine;
using System.Collections;
public class AI_follow : MonoBehaviour
{
// Agent idzie do gracza, jesli dzieli ich okreslony dystans
private GameObject player;
public NavMeshAgent agent;
void Update () {
player = sCharactersManager.characters[0].gameObject;
agent = GetComponent<NavMeshAgent>();
if(!gameObject.GetComponent<Character>().isDead)
{
if(agent.isOnNavMesh)
{
agent.SetDestination(player.transform.position);
if(Vector3.Distance(player.transform.position,transform.position) > 1.5f)
{
agent.Resume();
}else{
agent.Stop();
}
}
if(Vector3.Distance(player.transform.position,transform.position) < 5)
{
Vector3 lookPos = new Vector3(player.transform.position.x, gameObject.transform.position.y, player.transform.position.z);
gameObject.transform.LookAt(lookPos);
}
}else{
agent.Stop();
}
}
}