x


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);
}
more ▼

asked Nov 01 '11 at 03:53 AM

PuzzleBox gravatar image

PuzzleBox
46 15 17 17

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?

Nov 01 '11 at 04:08 AM gfr

so I must put script that effects animation on an object that has a collider and animation component?

Nov 01 '11 at 04:22 AM PuzzleBox

Yes, your script has to be on a gameobject with a collider.

Nov 01 '11 at 04:32 AM gfr
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.
more ▼

answered Nov 01 '11 at 04:31 AM

gfr gravatar image

gfr
451 1 3 4

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Nov 01 '11 at 09:35 AM

roamcel gravatar image

roamcel
1.2k 37 40 44

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5077
x3783
x3738
x983

asked: Nov 01 '11 at 03:53 AM

Seen: 1223 times

Last Updated: Nov 01 '11 at 09:35 AM