-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManipulatableScript.cs
executable file
·113 lines (98 loc) · 2.96 KB
/
ManipulatableScript.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
using UnityEngine;
using System.Collections;
public class ManipulatableScript : MonoBehaviour {
public float desiredHeight;
public float MIN_ALLOWED_HEIGHT = -25.0f;
public float MAX_ALLOWED_HEIGHT = 25.0f;
public int ownerID = -1;
public int ID;
public PlayerScript owner;
NetworkView theView;
// Use this for initialization
void Start ()
{
desiredHeight = transform.position[1];
theView = this.gameObject.GetComponent(typeof(NetworkView)) as NetworkView;
}
public void setID(int id)
{
ID = id;
}
[RPC]
public void setManipulatableOwner(PlayerScript p)
{
if (p.getID() == ownerID)
{
return;
}
if(owner != null)
owner.setManipulatableAsNotOwned(this);
owner = p;
ownerID = p.getID();
owner.setManipulatableAsOwned(this);
this.renderer.material.color = owner.getColor();
}
[RPC]
public void setManipulatableOwnerID(int id)
{
Debug.Log("setting prism owner id: " + id);
ownerID = id;
GameObject[] taggedAsPlayers = GameObject.FindGameObjectsWithTag("Player");
Debug.Log("number of players: " + taggedAsPlayers.Length);
for (int i = 0; i < taggedAsPlayers.Length; i++)
{
PlayerScript ps = taggedAsPlayers[i].GetComponent(typeof(PlayerScript)) as PlayerScript;
if (ps.getID() == ownerID)
owner = ps;
}
owner.setManipulatableAsOwned(this);
this.renderer.material.color = owner.getColor();
}
public void makeNotOwned()
{
ownerID = -1;
owner = null;
this.renderer.material.color = Color.white;
}
// Update is called once per frame
void Update()
{
}
void FixedUpdate()
{
float heightDifference = transform.position[1] - desiredHeight;
if (Mathf.Abs(heightDifference) <= .05f && Mathf.Abs(heightDifference) >= .001f)
{
transform.position = new Vector3(transform.position[0], desiredHeight, transform.position[2]);
//transform.position += new Vector3(0.0f, heightDifference, 0.0f);
}
else if (Mathf.Abs(heightDifference) > .05f)
{
if (heightDifference > 0)
{
transform.position += new Vector3(0.0f, -0.05f, 0.0f);
}
else
{
transform.position += new Vector3(0.0f, 0.05f, 0.0f);
}
}
}
public void addDesiredHeight(float h)
{
desiredHeight += h;
if (desiredHeight > MAX_ALLOWED_HEIGHT)
desiredHeight = MAX_ALLOWED_HEIGHT;
else if (desiredHeight < MIN_ALLOWED_HEIGHT)
desiredHeight = MIN_ALLOWED_HEIGHT;
}
//public void networkRaiseHeight(float h)
//{
// theView.RPC("raiseAPrism", RPCMode.All,
//}
[RPC]
public void raiseAPrism(float height)
{
addDesiredHeight(height);
}
}