- Home /
Question by
LpHiX · Feb 20, 2017 at 10:22 AM ·
networkinginstantiatenetworkvariablevariables
How to create a object that can only be seen by one player?
I am instantiate a object, then have it hidden from other players, how do I do this? I am currently trying to set it to an id that is the same as the player that is creating it, then I hide it from everybody. When I try to debug this, I debugged the id of the object and the second player's id is null, anybody knows why?
public class ObjectID : MonoBehaviour {
public void SetObjID(string _player, BuildingSystem _bs)
{
string objID = _player;
BuildingSystem bs = _bs;
GameObject _gameObject = this.gameObject;
bs.hidePreview(objID, _gameObject);
Debug.Log(20000);
Debug.Log(objID);
}
}
That's my script on the object.
public void hidePreview(string _objectID, GameObject preview)
{
if (_objectID != playerID)
{
preview.GetComponent<Renderer>().enabled = false;
Debug.Log(100000);
}
Debug.Log(300000);
}
This is the script I use to hide it
GameObject curPrev = Instantiate(currentObject.preview, currentPos, Quaternion.identity) as GameObject;
curPrev.GetComponent<ObjectID>().SetObjID(playerID, this);
This is the script I use to create the object.
Anybody help please? The ID for the local client works, but for the other one it just says "Null" when I Debug.Log(objID);
Comment