Hi all, I am a beginner in Unity. I finished making a Pong game, and one mechanic I would like to add is for the player’s pong rackets to become smaller and smaller as time passes within each round. May I know what is the best way to implement this mechanic?
The most straightforward way is to adjust the transform scale of the rackets.
A component like this could be put onto your rackets.
public class RacketScaler : MonoBehaviour
{
public float scaleLossRate;
void Update()
{
transform.localScale = Vector3.one * (1f - Mathf.Lerp(0f, .5f, Time.timeSinceLevelLoad * scaleLossRate));
}
}
Over time, this make the rackets up to 50% smaller. The public parameter scaleLossRate probably needs to be very small. Time.timeSinceLevelLoad presumes that you reload the level when restarting, so that could be replaced if something like “time since last round begun” is more appropriate for you.