Leon Homburg
Leon Homburg

Reputation: 31

What's the best way to trigger an animation from the input of another object?

I'm new to unity and c#.

When i air tap on the left sphere, the plane and the right sphere should appear.

enter image description here enter image description here

I figured that an OnPointerClicked event on the left sphere the animation of the plane and right sphere triggers (with an if/else statement). Is this the way to go? If so, how do i do that?

Or is there an easier method?

Thats the script of the left sphere: enter image description here

Upvotes: 1

Views: 478

Answers (1)

knh190
knh190

Reputation: 2882

Read this: IPointerClickHandler.OnPointerClick

You need to implement the interface, i.e. IPointerClickHandler in your MonoBehaviour class. When you click on the object in game, it will send a click event to EventSystem, which triggers the function body you have in your OnPointerClick method.

So as the doc mentioned, also make sure you have an EventSyetem (an empty game object with the script attached, or attach the component to your main camera).

Upvotes: 1

Related Questions