I’m new in Unity. I want to change scale (size i.e. width , height ) during run-time of a gameobject. How can I possibly do that? I’ve used localscale function it but didn’t work properly. May be I didn’t use it properly . Any help ?
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
GameObject rotater;
void Start () {
rotater = GameObject.Find("Cube");
}
public void btnChangeHeight() {
rotater.gameObject.transform.localScale += newVector3(0,50,0);
}
}
While button is pressed (repeatButton)
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
GameObject rotater;
void Start () {
rotater = GameObject.Find("Cube")
}
void OnGUI() {
if (GUI.RepeatButton (new Rect (40, 60, 70, 21), "Height")) {
rotater.gameObject.transform.localScale += new Vector3(0,1,0);
}
}
}
That is definitely not the easiest way, using the rigid body is unnecessary. Instead, you can just write transform.localScale += new Vector3(0.05f, 0.05f, 0.05f);