# Assigning script to multiple objects

So I have multiple gameobjects that needs to be interactable and I've put them all in one gameobject container. But the thing is I still have to attach the script into each of the gameobjects that needs to be interactable for it to work and that seems kinda iffy when a scenario comes that I have to add more gameObjects.

Is it possible to just put the script in the container object? I tried this on my container object and I'm pretty sure I'm doing something wrong.

public GameObject spriteHandler;
GameObject sprite1;
GameObject sprite2;
GameObject sprite3;
private void Start()
{
sprite1 = spriteHandler.transform.GetChild(0).gameObject;
sprite2 = spriteHandler.transform.GetChild(1).gameObject;
sprite3 = spriteHandler.transform.GetChild(2).gameObject;
}
void OnMouseDown()
{
Debug.Log("Clicked");

}

• What behaviour would you like the parent script to have? Right now this looks pretty placeholder, so it's hard to guess where you're planning to develop it from here. Dec 10, 2020 at 0:17
• Basically what's going to be in OnMouseDown() is a method from another script that opens up the dialogue when you click the sprite. That works when I assign the script with OnMouseDown() on the gameobjects individually. I'm just looking for a way so I only need to assign this script with OnMouseDown() on the parent object. Maybe I should use events? Dec 10, 2020 at 1:16
• And is it the same dialogue no matter which sprite you click, or a different dialogue depending on the sprite? Be sure your question contains a complete description of what you need, so you don't get incomplete answers. Dec 10, 2020 at 1:17
• My bad. Yeah, it's basically the same dialogue. What sprite you click doesn't matter. Dec 10, 2020 at 1:18