Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

OnMouse Events not firing on a Clone

$
0
0
I have a GameObject that consists of a plane and a nested plane. I am trying to (for now) simply change the color on mousedown. if I drop the prefab on the scene and play, it works fine. But after I add the object at runtime it does not respond. code for adding object: for (int i = 0; i < Size.x; i++) { for (int j = 0; j < Size.y; j++) { Cells [i, j] = (GameObject)Instantiate (partblock); Cells [i, j].transform.position = new Vector3 (i * partSize - (Size.x * (partSize - 1) / 2f), j * partSize - (Size.y * (partSize - 1) / 2f), 1); Cells [i, j].GetComponentInChildren ().Cell = new Point (i, j); } } code that is attached to object: bool overCell; void OnMouseDown () { overCell = true; } void Update () { if (overCell) renderer.material.color = color.red; } Any ideas? FYI: the object has a collider, and it is in front of all other objects.

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>