Y
Y
yraiv2020-05-28 11:34:15
Unity
yraiv, 2020-05-28 11:34:15

How to change the scale of an object by equal parts depending on the number?

How to resize an object by equal fractions depending on the original number.
An object has an initial number on which it must depend.
For example, if int Number is initially given, then the scale value is bound to that number.
For example, for x scale = 5 and number = 5, if number = 4, then scale should also be equal to 4 and so on up to 0, how is this done?
But it must not exceed a certain number, for example, 10.
If number is initially equal to 20, then scale must still not exceed 10. If number is 18, then scale must be equal to 9, etc.
I started doing this:

public GameObject KakoitoObject;
 public int Number;
 if (Number = 5)
{
  KakoitoObject.transform.localScale = new Vector3 (5,0,0) ;
}
 if (Number = 4)
{
  KakoitoObject.transform.localScale = new Vector3 (4,0,0) ;
}


but I realized that it’s a bad idea in general, because I want to be able to change nubmer from the inspector, and in this code I will have to add more lines for each new number

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-05-28
@freeExec

KakoitoObject.transform.localScale = new Vector3 (Number,0,0) ;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question