- Home /
Mouse click on a game object to animate the main camera.
Hi, first things first, I'm building a solar system for a school project. People will be able to have a look at the planets and get information about them. While observing a planet, they will be able to click on the planet behind to fly over (camera animation) to focus and get more information about it. My problem is, I am very new to Unity platform and my coding abilities are very limited.
How can I trigger the animation that is attached to the main camera when I click on the game object? Do I have to create another camera and switch cameras when clicked on the other object?
I tried searching the forum, but I couldn't find a suitable script to plug-in to my scene's camera. Thank you in advance for your help!
Attach this script to your object (ObjectScript.js)
var cam : GameObject;
function Start()
{
cam=GameObject.Find("$$anonymous$$ain Camera");
}
function On$$anonymous$$ouseDown()
{
cam.GetComponent.<CameraScript>().Animate();
}
Attach this script to your camera (CameraScript.js)
function Animate()
{
anim.SetTrigger("youranimation");//configure it in your animator tab
}
Your answer
Follow this Question
Related Questions
How to run an animation mouse click. 2 Answers
Changing position of game object during animation 2 Answers
getting a object to slowly orbit 2 Answers
cut scene, in-game cinematic how to 1 Answer
How can a camera activate an animation 2 Answers