Multiple istance of the same script

Hi!
I’m trying to create a 2d platform scene and i need to place a script that animates multiple copies of the same gameObject. The problems that the script attached to it makes animating all gameObject with this script. How can i separate the behavior of every singular gameObject? Here’s the script

    using UnityEngine;
    using System.Collections;
    
    class GrassAnimationScript : MonoBehaviour 
    {
    
    	private bool onGrass;
    	public float grassRadius = 1;
    	public Transform groundCheck;
    	public LayerMask Grasses;
    	public Sprite sprite0;
    	public Sprite sprite1;
    	public float timer = 1;
    	public float timerSpeed= 1;
    	private bool wichSprite;
    	private SpriteRenderer myRenderer;
    	// Use this for initialization
    	void Start () 
    	{
    		myRenderer = gameObject.GetComponent<SpriteRenderer>();	
    	}
    	
    	// Update is called once per frame
    	
    	void Update()
    	{
    		onGrass = Physics2D.OverlapCircle (groundCheck.position, grassRadius, Grasses);
    		
    		
    		if(onGrass == true && Input.GetAxis("Horizontal") != 0)
    		{
    			
    			if (wichSprite == true)
    			{
    				myRenderer.sprite = sprite0;
    				timer -= Time.deltaTime*timerSpeed;
    				if (timer <= 0)
    					wichSprite = false;
    			}
    			else if (wichSprite == false)
    			{
    				myRenderer.sprite= sprite1;
    				timer += Time.deltaTime*timerSpeed;
    				if (timer >= 1)
    					wichSprite= true;
    			}
    		}
    		else
    		{
    			myRenderer.sprite = sprite0;
    			timer = 1;
    		}
    	}	
    }

Same result using simple animator controller.

you define a public bool, let’s say isAnimating. check the ones on editor that will animate.

and put the following.

public bool isAnimating;

then

if(isAnimating){
 //animation method
}

try something like this, just add the gameobjects you want to animate on the childObjects variable, and namespace for Collections.Generic. . Let me know if it works.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GrassAnimationScript : MonoBehaviour {

    public List<GameObject> childObjects;
    public float grassRadius = 1;
    public Transform groundCheck;
    public LayerMask Grasses;
    public Sprite sprite0;
    public Sprite sprite1;
    public float timer = 1;
    public float timerSpeed = 1;
    private bool wichSprite;
    
    // Use this for initialization
    void Start()
    {
        
    }

    // Update is called once per frame

    void Update()
    {
        
       

        foreach (GameObject go in childObjects)
        {
           SpriteRenderer myRenderer = go.GetComponent<SpriteRenderer>();
           bool onGrass = Physics2D.OverlapCircle(groundCheck.position, grassRadius, Grasses);


           if (onGrass == true && Input.GetAxis("Horizontal") != 0)
           {

               if (wichSprite == true)
               {
                   myRenderer.sprite = sprite0;
                   timer -= Time.deltaTime * timerSpeed;
                   if (timer <= 0)
                       wichSprite = false;
               }
               else if (wichSprite == false)
               {
                   myRenderer.sprite = sprite1;
                   timer += Time.deltaTime * timerSpeed;
                   if (timer >= 1)
                       wichSprite = true;
               }
           }
           else
           {
               myRenderer.sprite = sprite0;
               timer = 1;
           }
        }

        }

        
}

Are you sure GroundCheck is not the same for everybody? Maybe you accidentally setted the same for every instance, and as far as i undestand what you are wanting to do, that property should be different for each instance, i assume is some sort of dummy in the foots of the players.

Are you controlling various objects at the same time?, because the Input.GetAxis will move everybody.