-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAICharacterControl.cs
More file actions
38 lines (31 loc) · 1011 Bytes
/
Copy pathAICharacterControl.cs
File metadata and controls
38 lines (31 loc) · 1011 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
31
32
33
34
35
36
37
38
using System;
using UnityEngine;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof (NavMeshAgent))]
[RequireComponent(typeof (ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour {
public NavMeshAgent agent { get; private set;
public ThirdPersonCharacter character { get; private set; }
public Transform target;
private void Start() {
agent = GetComponentInChildren<NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();
agent.updateRotation = false;
agent.updatePosition = true;
}
private void Update() {
if (target != null) {
agent.SetDestination(target.position);
// use the values to move the character
character.Move(agent.desiredVelocity, false, false);
}
else {
character.Move(Vector3.zero, false, false);
}
}
public void SetTarget(Transform target) {
this.target = target;
}
}
}