- Home /
Question by
SuperReaper1999 · Dec 31, 2015 at 02:01 AM ·
unity 5javascriptnetworking
Doors only open when host triggers it
The doors open only if the host is the one that tries to open it and I can't figure out why here is the code that I have
public class DoorScript extends NetworkBehaviour {
var smooth = 2.0;
var DoorOpenAngle = 90.0;
var defaultRot : Vector3;
var openRot : Vector3;
@SyncVar
var open : boolean = false;
function Start(){
defaultRot = transform.eulerAngles;
openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
}
function Update (){
if(open && transform.eulerAngles != openRot)
{
CmdOpenDoor();
}
else if (!open && transform.eulerAngles != defaultRot)
{
CmdCloseDoor();
}
}
function ChangeOpenState(){
open = !open;
}
@Command
function CmdOpenDoor(){
RpcOpenDoor();
}
@Command
function CmdCloseDoor(){
RpcCloseDoor();
}
@ClientRpc
function RpcOpenDoor () {
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
}
@ClientRpc
function RpcCloseDoor () {
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth);
}
}
the function ChangeOpenState is called in another script when the player is looking at a door
I'm sorry if this is a stupid question
Comment
Best Answer
Answer by SuperReaper1999 · Jan 02, 2016 at 01:33 PM
I fixed this issue by moving the Command to a different script that was active only on the player.
Your answer
Follow this Question
Related Questions
How do i share data between computers 0 Answers
Sending an RPC 1 Answer
OnServerStart not working in Build. Works in editor 1 Answer
uNet horrible lagg (even on local servers) 0 Answers
Array bug or script error 1 Answer