Im trying to make a tetris game, where the host moves his blocks, and the client moves his.
Client on the left, host on the right.
So the host is suppost the move the object with the "playerObject" tag. The client is suppost to move the object with the "enemeyObject" tag.
Seems like the client is not using the "enemyObject" tag, but is moving the playerObject object.
The code for spawning in the objects:
[ClientRpc]
void RpcSetTag()
{
playerBlock.transform.gameObject.tag = "playerObject";
enemyBlock.transform.gameObject.tag = "enemyObject";
}
IEnumerator SpawnObjects()
{
rnd = Random.Range(0, objects.Length);
playerBlock = Instantiate(objects[rnd], spawnPointPlayer.transform.position, objects[rnd].transform.rotation);
enemyBlock = Instantiate(objects[rnd], spawnPointEnemy.transform.position, objects[rnd].transform.rotation);
NetworkServer.Spawn(playerBlock);
NetworkServer.Spawn(enemyBlock);
RpcSetTag();
yield return new WaitForSeconds(6f);
CmdStartTimer();
}
the code to move the objects:
void Update()
{
if (isServer)
{
Debug.Log("SERVER");
Server = true;
}
if (!isServer)
{
Client = true;
Debug.Log("CLIENT");
}
if (Server == true)
{
block = GameObject.FindGameObjectWithTag("playerObject");
Debug.Log(block);
}
if (Client == true)
{
block = GameObject.FindGameObjectWithTag("enemyObject");
Debug.Log(block);
}
if (pressingL == true)
{
CmdMoveLeft();
Debug.Log("MOVE LEFT");
}
if (pressingR == true)
{
CmdMoveRight();
Debug.Log("MOVE RIGHT");
}
if (Input.GetKey(KeyCode.D))
{
Debug.Log("D");
CmdMoveRight();
}
if (Input.GetKey(KeyCode.A))
{
Debug.Log("A");
CmdMoveLeft();
}
if (Input.GetKeyDown(KeyCode.E))
{
CmdRotateRight();
//background.transform.position = new Vector3(0.01f, 0, 0);
//background.transform.Rotate(-90, 0, 0);
}
if (Input.GetKeyDown(KeyCode.Q))
{
CmdRotateLeft();
//background.transform.position = new Vector3(0.01f, 0, 0);
//background.transform.Rotate(+90, 0, 0);
}
}
[Command]
public void CmdRotateLeft()
{
block.transform.Rotate(-90, 0, 0);
}
[Command]
public void CmdRotateRight()
{
block.transform.Rotate(+90, 0, 0);
}
[Command]
public void CmdMoveLeft()
{
block.transform.Translate(Vector3.left * 1f * Time.deltaTime, Space.World);
}
[Command]
public void CmdMoveRight()
{
block.transform.Translate(Vector3.right * 1f * Time.deltaTime, Space.World);
}