Expand Parent Object When Child Object Is Touched?

Hello. I am having troubles with my game and need some help figuring it out. I have made a script that expands an object when it is touched. The script used is

#pragma strict
public var localScale: Vector3;

function OnMouseDown() {

         transform.localScale += new Vector3(1f, 1f, 0);

I am using Event trigger to have this used. The real problem I have is that I want it that every object within a folder ( An empty game object ) to expand when that one object is touched. I am trying to stick to Event trigger but it only expands the one object. This may be confusing for one to see, so if there are any questions, please ask. Thank you.

The game is in 2D and is intended for the Android.

Assuming you have all these objects parented to the empty gameObject just go

  public Transform parent;

void OnMouseDown()
    		for(int i =0;i<parent.childCount;i++)
    			parent.GetChild(i).localScale = parent.GetChild(i).localScale+new Vector3(1f,1f,0);

It’s c# but the logic should be similar

i recently seen this question about local scale a couple other times now. I think they changed the example in the unity scripting API in the last few months. kinda looks like that’s what you used. IDK might have something to do with these questions.

anyways, The way I code it from the old example always works: here is three different working examples. try it this way instead for javascript.




it works just like transform.position or transform.rotation

so by default all the children scale with the parent.
if you get the code right, you don’t need to do this to children unless you want them to scale seperatly.