-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRatAI.cs
67 lines (61 loc) · 1.69 KB
/
RatAI.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class RatAI : MonoBehaviour
{
public float attackDistance = 3f;
public float movementSpeed = 4f;
public float move;
public float npcHP = 100;
//How much damage will npc deal to the player
public float npcDamage = 5;
public float attackRate = 0.5f;
//[HideInInspector]
private Transform playerTransform;
public Transform enemyTransform;
[HideInInspector]
//public SC_EnemySpawner es;
NavMeshAgent agent;
float nextAttackTime = 0;
Rigidbody r;
public bool enemyIsDead = false;
public bool damagetaken = false;
private GameMgr gamemanagerscript;
// Start is called before the first frame update
void Start()
{
gamemanagerscript = GameObject.Find("GameManager").GetComponent<GameMgr>();
agent = GetComponent<NavMeshAgent>();
agent.stoppingDistance = attackDistance;
agent.speed = move = movementSpeed;
r = GetComponent<Rigidbody>();
r.useGravity = false;
r.isKinematic = true;
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
}
// Update is called once per frame
void Update()
{
agent.speed = movementSpeed;
if (agent.remainingDistance - attackDistance < 0.01f)
{
if (Time.time > nextAttackTime)
{
nextAttackTime = Time.time + attackRate;
}
}
//Move towardst he player
agent.destination = playerTransform.position;
transform.LookAt(new Vector3(playerTransform.transform.position.x, transform.position.y, playerTransform.position.z));
if (gamemanagerscript.islastshot)
{
movementSpeed = 0;
Destroy(this.gameObject);
}
if (gamemanagerscript._timeRemaining == 0)
{
Destroy(this.gameObject);
}
}
}