Hello,
there were many similar topics. I read them all and I still cant do this. The problem is I got two scripts. In script A Im spawning a clone of prefab like this:
void SpawnPlayer()
{
float x = Random.Range(-5f, 5f);
Network.Instantiate(playerPrefab, new Vector3(2.144f+x, 3f, 30.516f+x), Quaternion.identity, 0);
}
This scrip is making a clone of playerPrefab and I want in script B to use this clone
using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour {
public GameObject Gracz;
void Update ()
{
if( networkView.isMine )
{
Vector3 temp = Gracz.transform.position;
temp.y += 20;
transform.position = temp;
}
}
}
and I want that GameObject called Gracz to be that Instantiated clone. How to do this?
EDIT:
Ive tried something like that:
public GameObject Gracz;
into
static public GameObject Gracz;
and
Network.Instantiate(playerPrefab, new Vector3(2.144f+x, 3f, 30.516f+x), Quaternion.identity, 0);
into
CameraMovement.Gracz = Network.Instantiate(playerPrefab, new Vector3(2.144f+x, 3f, 30.516f+x), Quaternion.identity, 0);
Assets/NetworkManager.cs(42,32): error CS0266: Cannot implicitly convert type UnityEngine.Object' to
UnityEngine.GameObject’. An explicit conversion exists (are you missing a cast?)
;(
EDIT2:
I used cast “as GameObject” but now all players uses the same camera sticked to the first clone (made by server).
EDIT3;
There is another strange thing. If there are two people on the server one of them (server) controls ball A and (client) controls ball B. This works. I display “networkView.owner” above players and there is magic. Both server and client cameras follows the same ball. The ball A (servers one). But server displays 0 above the ball and client displays 1 so it looks like both of them thinks the ball A is theirs. Even tho moving the balls works corectly.