- Home /
UI control applied to object is not working on its duplicate game object.
I have created button. which perform move operation on gameObject & it works fine. then I created duplicate of it & want operation to work as well for duplicated object also. but only original object is being affected. button action is not working on duplicated object.
my doubt is: as I have assigned original object to button. then how will same button click for all the duplicated objects.
I want, once control is working on original object, then as many duplicate object I create. control should work on all the object. As I can not assign all the duplicated objects to button.
Answer by simiel7 · May 18 at 09:29 PM
Hi @appsandro
If I'm not mistaken you created a button and added an OnClick() action in the Editor.
If this is the case, then you can create a separate Monobehaviour, like ControlGameObjects and create a method in it, for example MoveObjects(), which will be added as an action in the OnClick() (instead of that one you added).
And in the ControlGameObjects class you can collect the game objects you want to use and in the MoveObjects() you can write any code you want to executed when the button was pressed.
E.g.
// Add this monobehaviour to a separate gameObject in the Scene view in the Editor, different than those which will be moved by the button
public class ControlGameObjects : MonoBehaviour
{
// In the editor you can drag and drop any game objects here where you want to be affected by the button
[SerializeField] private GameObject[] gameObjects;
// Select this method in the button action's OnClick()
public void Movebjects()
{
for(var go : gameObjects)
{
// Do whatever you want with the objects move, rotate, scale, etc.
}
}
}
Your answer

Follow this Question
Related Questions
Trying to manage an Animation. AnimationState.time doesn't adjust the animation 1 Answer
How to display exact video by index, property on button click 0 Answers
Rotation Code Help 3 Answers
I need to alter each child object individually 1 Answer
Why is checking button click in Unity done this way? 1 Answer