- Home /
Reacting to Mouse animation...
I'm trying to make animations that react to the player's mouse. I looked all over the unity reference site and nothing works. What am I missing?
function Update () {
}
function OnMouseEnter () {
animation.Play("Element 1");
yield WaitForSeconds (1);
animation.Play("Element 0");
}
function OnMouseDown () {
animation.Play("Element 2", PlayMode.StopAll);
}
Are the functions called at all (check with some Debug.Log()
). If not, do you have a collider on those objects? Are they on the "ignore raycast" layer?
so I must put script that effects animation on an object that has a collider and animation component?
Answer by gfr · Nov 01, 2011 at 04:31 AM
First thing to check is wether the functions are called at all, e.g. using Debug.Log()
.
If they are not:
Check that you have a collider on your object, otherwise `OnMouseEnter()`/
OnMouseDown()
/... will not be called:OnMouseEnter is called when the mouse entered the GUIElement or Collider.
Beware that they are not called for objects on the "Ignore Raycast" layer.
Answer by roamcel · Nov 01, 2011 at 09:35 AM
All 3D interaction between gameobjects and the mouse needs be done through COLLIDERS. Colliders are responsible of intercepting events between gameobjects and the world, basically.
1 add a collider of any type to your gameobject
2 add the following code in a c# script that you attach to the gameobject
void OnMouseDown() {
Debug.Log("AHAHA stop clicking me!");
}
3 in play mode click over the gameobject
Your answer
Follow this Question
Related Questions
Third Person Help 4 Answers
Animation Problems 1 Answer
Character controller problem? 2 Answers
Get GameObject That Was Last Clicked? 2 Answers
uSequence disabling mouselook on build? 0 Answers