- Home /
[Solved]Instantiated objects with the same Animator
I have an item in my game which the player can spawn and place. It has an animator with the bool option "Click". If I have 10 items spawn, if you click on just one of them, the bool option "Click" is changed for all 10 items and they all animate together. I want only the object you click to animate.
This code is in the script applied to each instantiated object.
Animator animator;
void Start () {
Debug.Log(colliderB);
}
void Update () {
if(Input.GetMouseButtonDown(0)){
if(animator && placed)
{
if(objectAnimClick == 0){
animator.SetBool("Click", true);
objectAnimClick++;
}else{
animator.SetBool("Click", false);
objectAnimClick--;
}
}
}
Any help would be appreciated, I'm not so great at animations in Unity just yet, Cheers :)
To solve your problem you are either going to have to use On$$anonymous$$ouseDown() to detect your click, or you are going to have to do Raycasting() and then use the collider of the object hit. Right now, a mouse click anywhere (even not on your objects), will trigger the code. Lots of example on UA of both Raycasting and On$$anonymous$$ouseDown().
@$$anonymous$$ayaYT ins$$anonymous$$d of putting "[Solved]" in the title, you should close the question.
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Can you help solve the following error? 1 Answer
Mecanim. Why cant I get current state name? 1 Answer
Instant animation transition 4 Answers
How to manually update animator? 2 Answers