Hi everybody,
I’m stuck with a simple function that it’s similar to this example:
One gray cube in scene (not respawned just a single static cube in all clients player without controls, nothing at all)
a script that would say: if press spacebar (in the local machine) make the cube blue in all clients.
i’ve tried following the simple multyplayer tutorial messing up with [SyncVar] and [Command] or (isServer)(isLocal)… Now i’ve restarted from scratch and write few line of code and put it in a empty gameobject
(that is my player Prefab).
Please can you help me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class serverCtrl : NetworkBehaviour {
public GameObject cube;
// Use this for initialization
void Start () {
cube = GameObject.Find("Cube");
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
changeColor();
}
}
void changeColor()
{
cube.GetComponent<MeshRenderer>().material.color = Color.red;
}
}