What I’m trying to accomplish: I have made a method for an object that checks to see if it existed during the level load, and if not, network instantiates a copy of itself and destroys the original. This means that the same object with a network view can either exist from the start, or be added during runtime and function essentially the same. I came up with this because adding objects with a network view during runtime didn’t notify connected clients.
The script is as follows:
public bool HereFromTheStart = false;
public bool NetworkInstantiated = false;
public string resourcePath = "carrot man resource";
void Start () {
if(networkView.isMine && !NetworkInstantiated){
if(!HereFromTheStart){
GameObject netMake = (GameObject)Network.Instantiate(Resources.Load(resourcePath,typeof(GameObject)),transform.position,Quaternion.identity,0);
netMake.GetComponent<carrotManPace>().NetworkInstantiated = true;
GameObject.Destroy(gameObject);
}
}
}
void OnLevelWasLoaded(){
HereFromTheStart = true;
}
The Problem: When dragging the object with this attached, the start function is run as soon as the object is in the scene, instead of when the mouse button is released as would make more sense. This means that the object is immediately destroyed and also immediately instantiates a copy of itself. This causes the drag action to grab another prefab and repeat, which results in a prefab-painting like effect.
How can I have the start function only run when I release the mouse button while dragging? Or is there another way to solve this?
What I’ve tried: Having the code run on mouse-button-up. Unfortunately this detects the mouse up only from the game, not from the scene editor, so it requires me to go between both and click the mouse to have the code run. This is not optimal.