Im trying to scale up and down an object constantly, nothing need to trigger it, i just need to be like that throught the whole game. I really dont know how to start.,Nothing is affecting the gameOject, i just need my cube to size up and size down constantly in my scene.
There are many different ways you can do this. My suggestion is the use of Mathf.PingPong function. This function takes a value and, increases and decreases the value between 0 and another value you specify.
It is very suitable for the situation of constantly increasing and decreasing as in your case. When you add the following script to an object, you will see that the object grows and shrinks between 2 and 5 on the y-axis.
public class ScaleController : MonoBehaviour
{
public float maxLength = 5;
public float minLength = 2;
private Vector3 defaultSize;
private void Start()
{
defaultSize = transform.localScale;
}
void Update()
{
float newSizeY = (Mathf.PingPong(Time.time, (maxLength-minLength)) + minLength);
transform.localScale = new Vector3(defaultSize.x, newSizeY, defaultSize.z);
}
}
The Time.time parameter is important because the function needs a self-incrementing parameter. You can adjust the values according to your needs and you can do the same thing on the axis you want.