- Home /
Script refering to more than one GameObject
Hello, I have a JavaScript that I use to change the text color of a 3D Text and it will be used to close the application later. Here is the code:
function OnMouseEnter()
{
renderer.material.color = Color.red;
}
function OnMouseExit()
{
renderer.material.color = Color.white;
}
function OnMouseUp()
{
}
This script is a component of a 3D text. I also have 3 .c4d files on my project. Each one contains a model (it's a bear) and a animation (made in Cinema 4D). The 2 animations are: Idle (like breathing) and death. I used the idle .c4d file to put the bear on the scene and the animation that was on that .c4d. On the other .c4d file, there is other animation, a death animation. What I want is that when "OnMouseUp()" occurs, the animation from the second .c4d (death) starts and then the application quit. I know I close the aplication with "Application.Quit();", what I want to know is how to create the stuff I texted here before.
Thanks in advance.
Answer by jogo13 · Jan 27, 2013 at 04:17 AM
You may want export the both animations onto the same model file. If you know the names of the animations you can play them like so.
var bear_animation = bearGameObject.GetComponent("Animation");
//you can play animations like so:
bear_animation.Play("idle");
//change it to death:
bear_animation.Play("death");
I downloaded the .c4d files (there are 33, I didn't create anyone, because I really can't do anything that looks good). How can I export the animations onto the same file in Cinema 4D? I'm starting with Unity and Cinema 4D (started 2 days ago).
I don't know how to use Cinema 4D, but it looks like you can add multiple animations to one model's Animation component using Animation.AddClip http://docs.unity3d.com/Documentation/ScriptReference/Animation.AddClip.html
But only one model is on the scene. Can a model play an animation from other model?
Your answer
![](https://koobas.hobune.stream/wayback/20220613091639im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
(C#) Problem with animations not playing 1 Answer
2d Character physics? 1 Answer
Alternative To "SetEditorCurve"? 1 Answer
Stopping animation affecting physics 0 Answers
Animation play on input, else play idle animation. 2 Answers