-
Notifications
You must be signed in to change notification settings - Fork 0
/
NINJA.cs
147 lines (117 loc) · 5.38 KB
/
NINJA.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NINJA : baddie {
Animator animator;
bool activated;
public float walkingspeed;
public float activationdistance;
public GameObject hitter;
public bool twodee;
float strafespeed;
int strafeinterval;
int strafecount;
int attackingcount;
public override void takehit(int strength)
{
if (!dead)
{
//GetComponent<enemyik>().looking = false;
gameObject.GetComponent<AudioSource>().Play();
health -= strength;
animator.speed = 1;
if (health <= 0)
die();
//gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false;
//gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = true;
//gameObject.GetComponent<UnityEngine.AI.NavMeshObstacle>().carving = true;
}
}
void die()
{
animator.speed = 0.2f;
enemynumber--;
hitter.active = false;
gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false;
animator.SetBool("dead", true);
dead = true;
Collider coll = gameObject.GetComponent<Collider>();
coll.enabled = false;
}
// Use this for initialization
void Start () {
enemynumber++;
strafeinterval = Random.Range(10, 100);
strafespeed = Random.Range(0, 0.5f);
animator = gameObject.GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate () {
{
if (!dead)
{
if (!activated)
{
if (Vector3.Distance(gameObject.transform.position, playermovement.target) < activationdistance)
{
activated = true;
gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = true;
gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().speed = walkingspeed;
animator.speed = walkingspeed / 3.5f;
animator.SetBool("RUN", true);
animator.SetBool("IDLE", false);
}
}
if (activated)
{
Vector3 targetDir = playermovement.target - gameObject.transform.position;
if (attacking == true)
{
attackingcount++;
if(gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().remainingDistance < 0.5f || attackingcount >300)
{
attackingcount = 0;
animator.SetBool("JUMP", false);
animator.SetBool("RUN", true);
hitter.active = false;
attacking = false;
animator.speed = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().speed / 3.5f;
gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().speed = walkingspeed;
this.gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().acceleration = 100;
}
}
if (attacking == false)
{
gameObject.transform.Translate(strafespeed/3, 0, 0);
strafecount++;
if (strafecount > strafeinterval)
{
strafecount = 0;
strafespeed = Random.Range(-0.2f, 0.2f);
}
gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().speed = walkingspeed;
animator.speed = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().speed / 3.5f;
hitter.active = false;
this.gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().destination = playermovement.target;
if (Vector3.Distance(gameObject.transform.position, playermovement.target) < 5f)
{
attacking = true;
animator.SetBool("JUMP", true);
animator.SetBool("RUN", false);
animator.speed = 1;
hitter.active = true;
Vector3 dest = gameObject.transform.position - playermovement.target;
this.gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().speed = walkingspeed * 2;
this.gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().acceleration = 200;
this.gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().destination = gameObject.transform.position - (dest*3);
}
}
}
}
}
if (twodee)
{
gameObject.transform.position = new Vector3(0, gameObject.transform.position.y, gameObject.transform.position.z);
}
}
}