I am making a game and I am trying to make it so not only the host of the server can see when you press “A” and a gameobject sets active and when you press “D” another gameobject setsactive. I have tried but am not succeeding
here is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Movement : NetworkBehaviour
{
public float movementspeed = 1f;
public float coolDown = 0.2f;
public float coolDownTimer;
[SyncVar]
public GameObject Joust1;
[SyncVar]
public GameObject Joust2;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (!isLocalPlayer)
{
return;
}
if (coolDownTimer > 0)
{
coolDownTimer -= Time.deltaTime;
}
if (coolDownTimer < 0)
{
coolDownTimer = 0;
}
if (Input.GetMouseButton(0))
{
transform.Translate(Vector2.up * 0 * Time.deltaTime);
transform.Translate(Vector2.right * 0f * Time.deltaTime);
transform.Translate(Vector2.left * 0f * Time.deltaTime);
}
else
{
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector2.left * 15f * Time.deltaTime);
RpcLeft();
CmdLeft();
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector2.right * 15f * Time.deltaTime);
RpcRight();
CmdRight();
}
if (Input.GetKeyDown(KeyCode.Space) && coolDownTimer == 0)
{
transform.Translate(Vector2.up * 150 * Time.deltaTime);
coolDownTimer = coolDown;
}
}
}
[Command]
public void CmdLeft ()
{
Joust1.SetActive(true);
Joust2.SetActive(false);
}
[Command]
public void CmdRight()
{
Joust1.SetActive(false);
Joust2.SetActive(true);
}
[ClientRpc]
public void RpcLeft()
{
if (!isServer)
{
Joust1.SetActive(true);
Joust2.SetActive(false);
}
}
[ClientRpc]
public void RpcRight()
{
if (!isServer)
{
Joust1.SetActive(false);
Joust2.SetActive(true);
}
}
}