- Home /
How to use one animation and Animator Controller on multiple objects? [2D]
I want to rotate object 90 degrees on every touch. I can't do it in script cause rotation should be slow and smooth. I made four animations (rotation90, rotation 180 etc.) It works perfectly but when I duplicated Animator component to another objects, It does't work properly. When I touch one object, every objects are rotating. How to fix it?
Also, is there any way to make animation that won't rotate to specific rotation, but will add 90 degrees to current z rotation so I can have one animation instead of four.
Can you paste the script that interacts with the animator?
Here it is:
function Update () {
if (Input.touchCount > 0)
{
var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint((Input.GetTouch(0).position)), Vector2.zero);
if (Input.GetTouch(0).phase == TouchPhase.Began) {
if(hit.collider != null && hit.transform.gameObject.tag == "OutTwo")
{
rotCount++;
RotationAnimation();
}
}
}
}
function RotationAnimation ()
{
var anim: Animator = outTwo.transform.gameObject.GetComponent(Animator);
if (rotCount == 1)
{
anim.SetBool("rotate360", false);
anim.SetBool("rotate90", true);
}
else if (rotCount == 2)
{
anim.SetBool("rotate180", true);
anim.SetBool("rotate90", false);
}
else if (rotCount == 3)
{
anim.SetBool("rotate270", true);
anim.SetBool("rotate180", false);
}
else if (rotCount == 4)
{
anim.SetBool("rotate360", true);
anim.SetBool("rotate270", false);
rotCount = 0;
}
}
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
2D sprite animation issue 0 Answers
Only animate rotation not position 1 Answer
2D animation diferent right and left 0 Answers
2D Animator: how to get rid the animation "blending" 0 Answers