Object Scaling

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectScaling : MonoBehaviour {
public float scaleAmount = 2.0f;
public Vector3 originalScale = Vector3.zero;

void Awake()
{
originalScale = this.transform.localScale;
}

void Update ()
{
if(Input.GetKeyDown(KeyCode.G))
{
EnableScale ();
}
if (Input.GetKeyUp (KeyCode.G))
{
DisableScale ();
}
}

public void EnableScale()
{
this.transform.localScale = new Vector3 (scaleAmount, scaleAmount, scaleAmount);
}

public void DisableScale()
{
this.transform.localScale = originalScale;
}

}

when i try to scale the object through input…it’s scaling and then jumping off the plane

If you have physics enabled, it’s probably causing a collision with the plane because your centerpoint is in the center of the object so it’s also growing downward. You could maybe position up on the y first.

Indeed, that’s quite possible. However, it’s worth noting that your original scale is Vector3.zero … unless your overrode that in the inspector :wink:

thanks for the reply…but how to stop that from happening…

If it’s bouncing because of physics, as the previous poster said, you can increase your object’s y position by the appropriate amount to max “space” for it to expand (scale).

  • also reset it when scaling … smaller.