-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeadEffect.cs
112 lines (81 loc) · 2.97 KB
/
DeadEffect.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
using UnityEngine;
using System.Collections;
public class DeadEffect : MonoBehaviour {
private float lastSynchronizationTime = 0f;
private float syncDelay = 0f;
private float syncTime = 0f;
private Vector3 syncStartPosition = Vector3.zero;
private Vector3 syncEndPosition = Vector3.zero;
private Quaternion roatation = Quaternion.identity;
private Quaternion qSrot = Quaternion.identity;
private Quaternion qErot = Quaternion.identity;
Rigidbody rigidBody;
// Use this for initialization
NetworkView nview;
Vector3 randomDirection;
NetworkManager nManager;
Color pColor;
public Material mat;
void Start ()
{
if (GetComponent<NetworkView>().isMine)
{
nview = GetComponent<NetworkView>();
nManager = GameObject.FindGameObjectWithTag("GM/NM").GetComponent<NetworkManager>();
pColor = new Color(nManager.vColor.x, nManager.vColor.y, nManager.vColor.z);
GetComponent<MeshRenderer>().material.color = pColor;
nview.RPC("DeathColor", RPCMode.All, nManager.vColor);
}
rigidBody = GetComponent<Rigidbody>();
randomDirection = new Vector3(Random.value, Random.value, Random.value);
GetComponent<Rigidbody>().AddForce(randomDirection * 250);
StartCoroutine(WaitToDespawn());
}
// Update is called once per frame
void Update ()
{
}
IEnumerator WaitToDespawn()
{
yield return new WaitForSeconds(15);
Network.Destroy(this.gameObject);
}
[RPC]
void DeathColor(Vector3 color, NetworkMessageInfo info)
{
MeshRenderer otherPlayerRenderer = info.networkView.GetComponent<MeshRenderer>();
Material otherPlayerMaterial = info.networkView.GetComponent<Material>();
Color nColor = new Color(color.x, color.y, color.z);
otherPlayerRenderer.material.color = nColor;
}
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Vector3 syncPosition = Vector3.zero;
Quaternion rot = Quaternion.identity;
if (stream.isWriting)
{
syncPosition = rigidBody.position;
rot = transform.rotation;
stream.Serialize(ref syncPosition);
stream.Serialize(ref rot);
}
else
{
stream.Serialize(ref syncPosition);
stream.Serialize(ref rot);
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
syncStartPosition = rigidBody.position;
syncEndPosition = syncPosition;
qSrot = transform.rotation;
qErot = rot;
}
}
private void SyncedMovement()
{
syncTime += Time.deltaTime;
rigidBody.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay);
transform.rotation = Quaternion.Lerp(qSrot, qErot, syncTime / syncDelay);
}
}