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