Hi all, I’ve been trying to figure this out but can’t figure it out. How do I spawn a object that is under the local player’s control? I’m using a poolmanager and trying to convert it, here’s my code
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.Collections;
using System.Collections.Generic;
public class GameObjectPoolManager : NetworkBehaviour {
public static GameObjectPoolManager current;
private List<GameObject> ObjectList = new List<GameObject>();
private bool WillGrow = true;
public List<GameObject> ObjectsToReadyUp = new List<GameObject>();
public float AmountToReady = 2;
public GameObject Test;
//For spawning locally controlled objects
public void Awake(){
WillGrow = true;
current = this;
}
public void Start() {
CmdCreateExtra();
}
[Command]
public void CmdCreateExtra() {
if (ObjectsToReadyUp != null) {
for (int i = 0; i < ObjectsToReadyUp.Count; i++) {
ClientScene.RegisterPrefab(ObjectsToReadyUp*);*
for (int w = 1; w < AmountToReady; w++) {
GameObject temp = null;
temp = (GameObject)Instantiate(ObjectsToReadyUp*, new Vector3(0, 100, 0), Quaternion.identity);*
ObjectList.Add(temp);
temp.SetActive(false);
NetworkServer.AddPlayerForConnection(GetComponent().connectionToClient, temp, (short)(ClientScene.localPlayers.Count + 1));
NetworkFinder.instance.SpawnedObjects.Add(temp.GetComponent());
}
}
}
}
[Command]
* public void CmdCreateObject(string GOName, Vector3 Position, Quaternion Rotation){*
* for(int i=0; i < ObjectList.Count; i++){*
if(ObjectList_.name == GOName || ObjectList*.name == GOName + “(Clone)”){
if(ObjectList.activeSelf == false){
ObjectList.SetActive(true);
ObjectList.transform.position = Position;
ObjectList.transform.rotation = Rotation;
}
}
}*_
* if (WillGrow) {*
* GameObject temp = null;*
temp = (GameObject)Instantiate(Resources.Load(GOName), Position, Rotation);
* ObjectList.Add (temp);*
NetworkFinder.instance.SpawnedObjects.Add(temp.GetComponent());
NetworkFinder.instance.GiveNetID();
NetworkServer.AddPlayerForConnection(GetComponent().connectionToClient, temp, (short)(ClientScene.localPlayers.Count+1));
* }*
* }*
[Command]
* public void CmdDestroyObject(GameObject GO){*
GO.SetActive(false);
* }*
* public void DestroyAfter(GameObject GO, float time){*
* StartCoroutine (DisableObj (GO, time));*
* }*
* public IEnumerator DisableObj(GameObject GO, float time){*
* yield return new WaitForSeconds (time);*
* if (GO != null) {*
GO.SetActive(false);
* }*
* }*
}