How to transform different 3d object with button

I am using vuforia and I have some problem with transform different 3d object with button
I used the code TargetTransformer but it only can transform one specific object.
However this code only can control one object,I know that if I need to control other object I can copy one more and change my object name. But it will become more button on the screen.
I want to use the same button to scale, rotate my 3 objects

the code is this
https://developer.vuforia.com/forum/faq/unity-how-can-i-transform-teapot

Say you want to change that function:

 if (GUI.Button(new Rect(50,0,140,70), "Scale Up"))
        {
            float oldScale = mTeapotTransform.localScale.x;
            float newScale = oldScale * 1.5f;
            mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
        }

You can see that the 2 first lines are about changing the scale, so you don’t need to touch that (unless you want a different scale for each object). Third (and last) line is about localScale so it is here that you change the scale of your object, you will hence want to copy that line as many times as objects you want to modify. Say you want to change 3 objects the code will look like that now:

if (GUI.Button(new Rect(50,0,140,70), "Scale Up"))
        {
            float oldScale = mTeapotTransform.localScale.x;
            float newScale = oldScale * 1.5f;
            mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
            mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
            mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
        }

But obviously since we only copy and pasted a line it won’t change an OTHER object, it will affect the same, so we have to change the name of the object that is called. Let’s say these 2 new objects are A and B, we now have:

 if (GUI.Button(new Rect(50,0,140,70), "Scale Up"))
        {
            float oldScale = mTeapotTransform.localScale.x;
            float newScale = oldScale * 1.5f;
            mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
            A.localScale = new Vector3(newScale, newScale, newScale);
            B.localScale = new Vector3(newScale, newScale, newScale);
        }

But now we have to tell the script who the hell A et B are (because right it’s wondering), so let’s go back to the start of the script where we can declare these gameobjects:

private Transform mTeapotTransform = null;

Let’s add our lines:

private Transform mTeapotTransform = null;
private Transform A = null;
private Transform B = null;

We are now very close, the script knows who are A and B but don’t know to which gameobject link them (since null means nothing), the start function is here for us (i put directly modified):

 // Use this for initialization
    void Start ()
    {
        GameObject teapot = GameObject.Find("teapot");
        if (teapot != null)
        {
            Debug.Log("Teapot found");
            mTeapotTransform = teapot.transform;
        }

GameObject whateverObjectInMyScene1 = GameObject.Find("whateverObjectInMyScene1");
        if (whateverObjectInMyScene1 != null)
        {
            Debug.Log("whateverObjectInMyScene1 found");
            A = whateverObjectInMyScene1.transform;
        }

GameObject whateverObjectInMyScene2 = GameObject.Find("whateverObjectInMyScene2");
        if (whateverObjectInMyScene2 != null)
        {
            Debug.Log("whateverObjectInMyScene2 found");
            B = whateverObjectInMyScene2.transform;
        }
    }

And that’s it ! Now that you have those new variables you can change the other buttons too, shouldn’t be very difficult :slight_smile: