V
V
Vortex242021-06-16 12:23:55
Unity
Vortex24, 2021-06-16 12:23:55

The scale value does not return to the default value, what should I do?

private bool sit = false;

if (Input.GetKey("s"))
{
sit = true;
}

if (sit)
{
transform.localScale = new Vector3(1, 0.5f, 1);

}
if (sit = false)
{
transform.localScale = new Vector3(1, 1, 1);
}

I want the scale value to return the default value after the key is released

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lipovnik, 2021-06-16
@Lipovnik

1. It is necessary that sitit takes the value false after releasing.
2. It would not be bad to repeat

R
RavQs, 2021-06-21
@RavQs

you can make things much simpler
[SerializeField] private float SittingValue;
private void Update()
{
OnSit();
}
public void OnSit()
{
if (Input.GetKey("s"))
{
transform.localScale = new Vector3(transform.localScale.x, SittingValue, transform.localScale.z);
}
else
{
transform.localScale = new Vector3(transform.localScale.x, 1f, transform.localScale.z);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question