/
motor.cs
74 lines (63 loc) · 2.13 KB
/
motor.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class motor : MonoBehaviour {
public GameObject[] target1 = new GameObject[3];
NavMeshAgent agent;
public GameObject target;
Rigidbody rbody1;
Animator anim;
float dst;
Vector3 cur;
public bool life1;
player plscr;
public GameObject gun,cameraa1;
public ParticleSystem blood, blood1,mugg;
camera cam1;
public bool on1;
void Start () {
agent = GetComponent<NavMeshAgent>();
rbody1 = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
life1 = true;
cam1 = cameraa1.GetComponent<camera>();
on1 = cam1.on;
anim.SetBool("on1", on1);
}
void Update () {
int i = Random.Range(0, 3);
Vector3 vec2 = target1[i].transform.position - transform.position;
Vector3 vec = transform.position - target.transform.position;
Vector3 vec1 = new Vector3(vec.x, 0, vec.z);
agent.stoppingDistance = 8f;
if (life1)
{
RaycastHit hit2;
if (vec.magnitude < 100f)
{
transform.forward = Vector3.SmoothDamp(transform.forward, new Vector3(-vec.x, 0, -vec.z), ref cur, 0.5f);
agent.SetDestination(target.transform.position);
}
if (vec.magnitude <= 8f)
{
transform.forward = Vector3.SmoothDamp(transform.forward, new Vector3(-vec.x, 0, -vec.z), ref cur, 0.5f);
}
if (Physics.Raycast(gun.transform.position, vec2, out hit2, 50) && vec1.magnitude <= 50f)
{
plscr = hit2.transform.GetComponent<player>();
if (hit2.transform.name == "ToonSoldier_WW2_demo_model")
{
mugg.Play();
plscr.health--;
}
}
}
else
{
anim.Play("DAMAGED01");
Destroy(gameObject, 2.3f);
}
anim.SetFloat("dst", vec.magnitude);
}
}