OnMouseDown() with Network Instantiated objects

I added a basic monobehaviour with an OnMouseDown() function to a network spawnable object . This is so the player can select the object at runtime by clicking on it.

The OnMouseDown() works when the object is in the scene at startup, but not if it's instantiated at runtime using PhotonNetwork.Instantiate()

Assistance is appreciated.

Snippit:

using UnityEngine;
using System.Collections;

public class Commandable : MonoBehaviour
{
public void OnMouseDown()
{
Debug.Log("OnMouseDown");
}
}

Comments

  • Hi @Maddnuss,

    if you want to instantiate an object across the network using PhotonNetwork.Instantiate(...) the prefab needs to have an attached PhotonView component. I guess when you try to instantiate your object, that the Instantiation call doesn't work at all. Please have a look at the console if any errors are thrown.

    If you have the object created with the scene, it should work fine if you use an Instantiation call from inside Unity's OnMouseDown function. However you should prevent users from creating multiple / too many objects.