Sometimes OnMouseDown() method in Unity executes, sometimes it does not

后端 未结 2 1358
半阙折子戏
半阙折子戏 2021-01-07 08:40

So I have this code attached to a Quad.

public class ShapeGrid : MonoBehaviour {

public GameObject[] shapes;

void Start(){
    GameObject[,] shapeGrid = ne         


        
2条回答
  •  一整个雨季
    2021-01-07 09:05

    Probably you have to add colliders to all of objects because OnMouse events are based on collisions. Here is detailed info: Unity Docs - OnMouseDown

    Edit: after some talks we find out that the problem was caused by Instantiate method.

    It's allways a better way to fill all of parameters in Instantiate method e.g

    Instantiate(prefab, Vector3.zero, Quaternion.Identity)

    if you want, you could change any of these parameters after instantiating object.

提交回复
热议问题