Question by
drippy cat · Sep 10, 2015 at 10:47 PM ·
animationprefab2d animation
All objects affected by myAnimator.SetTrigger("StartIdle") but I only want one affected
I have 2 instances of the same prefab animating across the screen, each with a 2D collider. If I touch one of them with my mouse then both have their Animator Trigger activated and they both go to their new animation. I need just the one I touched change its animation. The prefab has a script file with this in the Update loop:
if (Input.GetMouseButton(0))
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint((Input.mousePosition)),
Vector2.zero);
if (hit.collider != null)
{
if (myAnimator != null)
{
Debug.Log("Been hit");
myAnimator.SetTrigger("StartIdle");
//Destroy(gameObject);
Instantiate(SplatParticle,
new Vector3(myTransform.position.x, myTransform.position.y, myTransform.position.z),
Quaternion.identity);
Data.currentScore += points;
bugState = BugState.Waiting;
}
}
}
If I uncomment the Destroy(gameObject); line then just the clicked object gets destroyed. So I'm thinking it must be something I've done wrong when setting up my Animator, but other than that I'm stumped. Any help would be greatly appreciated.
Comment