Hi ,
Got a little problem here that I can’t solve by myself.
Heres is the code, all in one script
public class WarriorSpells : NetworkBehaviour {
[SyncVar]
private int MurWallnom;
private float CooldownSortWarriorA = 5f;
private float CooldownSortWarriorZ = 1f;
private float CooldownSortWarriorE = 2f;
private bool BoolenSortWarriorA = false;
private bool BoolenSortWarriorZ = false;
private bool BoolenSortWarriorE = false;
public GameObject MurWallPrefab;
private GameObject cloneClient;
public GameObject PrefabMurWallServeur;
public GameObject Warrior;
private GameObject clone;
private float ProjectionWallRepere = 0;
[Command]
public void Cmd_ApparitionMur()
{
MurWallnom = MurWallnom + 1;
clone = (Instantiate(MurWallPrefab, Warrior.transform.position, Warrior.transform.rotation) as GameObject);
clone.transform.parent = transform;
NetworkServer.Spawn(clone);
clone.transform.name = clone.transform.name + MurWallnom;
Debug.Log(clone.transform.name);
}
[Client]
void MurEnfantGuerrier()
{
Debug.Log("ClientEnfantWall");
cloneClient = GameObject.Find("MurWarrior(Clone)");
cloneClient.transform.name = clone.transform.name + MurWallnom;
cloneClient.transform.parent = transform;
Debug.Log("ClientEnfantWall2");
Destroy(clone);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.A))
{
if (BoolenSortWarriorA == false)
{
BoolenSortWarriorA = true;
Debug.Log("SortA");
Cmd_ApparitionMur();
MurEnfantGuerrier();
// StartCoroutine(CooldownSortA());
}
}
}
The error message is this :
Line 56 : NullReferenceException: Object reference not set to an instance of an object
That means that the line cloneClient = GameObject.Find("MurWarrior(Clone)");
hasent found anything
Problem is that MurWarrior(Clone) actually exist in the scene because it is spawned from the server
clone = (Instantiate(MurWallPrefab, Warrior.transform.position, Warrior.transform.rotation) as GameObject);
In the client scene, the name of the Gameobject is actually MurWarrior(Clone). Why does the engine dosent found the gameobject ?
Best regards,