- Home /
This question was
closed Jun 04, 2014 at 06:40 AM by
thornekey for the following reason:
The question is answered, right answer was accepted
Question by
thornekey · Apr 22, 2014 at 03:43 AM ·
c#networkingarraysdoors
Door Activator Button Array
Hi, I have a door and an activator button, but Id like to put the activator in an array so that if there are 2 or more and theyre both being stood on they then it will only open the door.
here is what i have so far:
as you can see it opens and closes as needed if i enter the trigger, but now i need it so that if the object activator is in the array u have to interact with that to open it :P
(its using RPCs because its multiplayer btw )
public Transform[] doorActivator;
private Vector3 pos1;
public Vector3 target1;
private Vector3 pos2;
public Vector3 target2;
public float speed;
void Start () {
pos1 = transform.position;
target1 = transform.position;
target1.y += 1.3f;
pos2 = transform.position;
target2 = transform.position;
target2.y -= 1.3f;
}
void OnTriggerEnter (Collider other) {
if (other.tag == "Player") {
networkView.RPC("DoorOpen", RPCMode.All);
}
}
[RPC]
void DoorOpen () {
foreach (Transform t in transform)
{
float speedFin = speed * Time.deltaTime;
if(t.name == "StandardDoor_TOP") {
t.transform.position = Vector3.MoveTowards(target1, pos1, speedFin);
}
if (t.name == "StandardDoor_BOTTOM") {
t.transform.position = Vector3.MoveTowards(target2, pos2, speedFin);
}
}
}
void OnTriggerExit (Collider other) {
if (other.tag == "Player") {
networkView.RPC("DoorClose", RPCMode.All);
}
}
[RPC]
void DoorClose () {
foreach (Transform t in transform)
{
float speedFin = speed * Time.deltaTime;
if(t.name == "StandardDoor_TOP") {
t.transform.position = Vector3.MoveTowards(pos1, target1, speedFin);
}
if (t.name == "StandardDoor_BOTTOM") {
t.transform.position = Vector3.MoveTowards(pos2, target2, speedFin);
}
}
}
Comment
Follow this Question
Related Questions
Editor forgets elements of array after saving changes to code 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Command method dont change variables on server 0 Answers
Understanding Unet attributes 2 Answers