-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveEnviroment.cs
68 lines (52 loc) · 1.49 KB
/
MoveEnviroment.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
using UnityEngine;
using System.Collections;
public class MoveEnviroment : MonoBehaviour {
// Use this for initialization
bool interact = true;
NetworkView nView;
public bool kill;
public Transform[] waypoints;
private int currentIndex;
private Transform currentWaypoint;
public float moveSpeed;
float minDistance = .01f;
void Start()
{
currentWaypoint = waypoints[0];
currentIndex = 0;
}
// Update is called once per frame
void Update()
{
if (interact == true)
{
MoveTowardWaypoint();
if (Vector3.Distance(currentWaypoint.transform.position, transform.position) < minDistance)
{
currentIndex++;
if (currentIndex > waypoints.Length - 1)
{
currentIndex = 0;
}
currentWaypoint = waypoints[currentIndex];
}
}
}
void OnTriggerStay(Collider other)
{
if (kill)
{
if (other.tag == "Player")
{
nView = other.gameObject.GetComponent<NetworkView>();
nView.RPC("TakeDamage", nView.owner, 1);
}
}
}
void MoveTowardWaypoint()
{
Vector3 direction = currentWaypoint.transform.position - transform.position;
Vector3 moveVector = direction.normalized * moveSpeed; // *time.Delts
transform.position += moveVector;
}
}