Hi everybody.
I am trying to get some code to work over the network.
The idea is that this code should work regardless of who does it. But it only works on the server. When I chance the RPCMode to Server it only works on the client,so that didn’t work also.
private var hitObjectPosition : Vector3;
private var hitObjectRotation : Quaternion;
//Set communication with gameplay code to know how many players are available.
private var gamePlay;
gamePlay = GetComponent(NetworkGamePlay);
private var ray;
private var hits : RaycastHit[];
private var objectRenderer;
function Update ()
{
if (Input.GetMouseButtonDown(0))
{
//Transform the mouse position on screen to a position in 3d enviroment.
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
networkView.RPC("ChangeColor", RPCMode.All);
}
}
@RPC
function ChangeColor ()
{
hits = Physics.RaycastAll (ray, 100.0);
// Change the material of all hit colliders
for (var i=0;i<hits.length;i++)
{
var hit : RaycastHit = hits[i];
objectRenderer = hit.collider.renderer;
if (objectRenderer)
{
//objectRenderer.material.shader = Shader.Find("Transparent/Diffuse");
objectRenderer.material.color = gamePlay.playerColors[gamePlay.playerTurn];
hitObjectPosition = hit.transform.position;
hitObjectRotation = hit.transform.rotation;
Destroy (hit.collider);
}
}
if (hits.length == 0)
{
hitObjectPosition = Vector3(0.0,0.0,0.0);
}
}