- Home /
How do I make a transform on a Child (added by script) apply to that Child instead of its Parent?
H'lo folks! I hope the day is going well for you. I whipped up a little toy project to (hopefully) make it obvious what I'm trying to ask. What's missing from it so that the circle is the only thing that moves?
I've got a MainControlScript that I use to control everything. This is its Start function:
gameObject.AddComponent<SpriteRenderer>();
square = GetComponentInChildren<SquareScript>();
circle = gameObject.AddComponent<CircleScript>();
circle.Initiate();
square.AddCircle(circle);
square.MoveCircle();
And here is the Initiate function in the Circle class:
string path = Application.dataPath + "/Images/Circle.png";
Sprite newSprite = LoadSprite(path);
GetComponent<SpriteRenderer>().sprite = newSprite;
GetComponent<SpriteRenderer>().enabled = true;
The circle appears just fine, but the movements get applied to MainControl (thus moving everything including the Diamond which is literally just sitting there on it's own doing nothing but looking not-so-pretty) instead of just the circle.
My question is this: what's missing from it so that the circle is the only thing that moves? I'm expecting that it's something fundamental in Circle's Initiate function, but I haven't been able to figure out what that is yet.
P.S. I know that this structure is definitely more complicated than it needs to be to accomplish simply moving a circle around on the screen. But suffice it to say that in my actual project both the "square" and the "circle" are responsible for handling enough other stuff that this separation is valid (at least to me). In any case, my big problem is that transforms on "Circle" (the Child generated at run time) apply to "MainControl" (the Parent) instead of "Circle" and that certainly seems like a thing I'll need to be able to fix in order to create anything remotely enjoyable.