How can I scale an object with keyinput and return old scale when I do not press like Mario crunch

The thing is I only want him to scale this 1 time when I key is pressed and only y should change.

void Update () {

	if (Input.GetKey("down"))

	{
		transform.localScale = new Vector3(0, 0.25f, 0)* Time.deltaTime;
	}

Ok, so the answer is simple. You are only providing an “if” statement for what would happen when the user presses “down”. But what would happen if the user releases it? How you wrote the code, nothing would happen. And this is because, as said before, you are only supplying an “if” statement to when the user is holding the button down.

To fix this, all you have to do is add an “else” statement after you close the “if”. After you opened up the “else” statement within it, write the code to make the character have normal size again. Speaking of size, I think the size you’re applying is wrong as well. You’re making the x and z sizes 0 which would make your character disappear, which I’m assuming you don’t want. Anyways, the code would look something like this:

void Update () {
     if (Input.GetKey("down"))
     {
         transform.localScale = new Vector3(1f, 0.25f, 1f) * Time.deltaTime;
     }
     else
     {
         transform.localScale = new Vector3(1f, 1f, 1f) * Time.deltaTime;
     }
}

Hope this helps! And if it did, kindly mark as answered. :slight_smile: