Hello,
Can anyone tell me on how I can scale an object (cube) by clicking it?.
When you click on screen, the cube appears and if you keep the button down, the cube continues to scale until you let go button.
Thanks.
Something like :
using UnityEngine;
public class MyClass : MonoBehaviour {
public GameObject cube;
public GameObject a;
void Start() {
cube = Resources.Load("cube") as GameObject;
}
void OnGUI()
{
if (GUILayout.Button("Spawn Cube"))
{
a = (GameObject)Instantiate(cube, transform.position, Quaternion.identity);
}
if (GUILayout.RepeatButton("UpScale"))
{
UpScale(a.transform.localScale);
}
if (GUILayout.RepeatButton("DownScale"))
{
DownScale(a.transform.localScale);
}
}
void UpScale(Vector3 scale) {
scale += new Vector3(0.1f,0.1f,0.1f);
a.transform.localScale = scale;
}
void DownScale(Vector3 scale)
{
scale -= new Vector3(0.1f, 0.1f, 0.1f);
a.transform.localScale = scale;
}
}