- Home /
Question by
BunniPlz · Feb 22, 2014 at 12:07 AM ·
mousedowncapsule collider
Odd Capsule Collider Behavior
I'm trying to use the OnMouseDown() function on a capsule that has a capsule collider. For some reason, it only detects the mouse down event when I click on the round ends of the capsule, and not when I click on the cylindrical portion.
The script also handles OnMouseDown() on two other left and right arrow objects. The arrows behave as intended, but not the capsule.
void OnMouseDown() {
if (objectName == "arrowLeft") {
Debug.Log ("left arrow clicked");
transform.Translate (new Vector3(-0.2f, 0, 0));
}
else if (objectName == "arrowRight") {
Debug.Log ("right arrow clicked");
transform.Translate (new Vector3(0.2f, 0, 0));
}
else if (objectName == "Capsule") {
Debug.Log ("Capsule clicked");
float r = Random.Range (0f, 1f);
float g = Random.Range (0f, 1f);
float b = Random.Range (0f, 1f);
Color randomColor = new Color (r, g, b, 1f);
renderer.material.color = randomColor;
}
}
Comment