Initial commit

This commit is contained in:
Ardella Malinda Sarastri
2025-07-10 17:06:42 +07:00
commit 72b8b42a0b
8149 changed files with 4223394 additions and 0 deletions

View File

@ -0,0 +1,26 @@
using UnityEngine;
public class ScaleToFitScreen : MonoBehaviour
{
private SpriteRenderer sr;
private void Start()
{
sr = GetComponent<SpriteRenderer>();
// world height is always camera's orthographicSize * 2
float worldScreenHeight = Camera.main.orthographicSize * 2;
// world width is calculated by diving world height with screen heigh
// then multiplying it with screen width
float worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
// to scale the game object we divide the world screen width with the
// size x of the sprite, and we divide the world screen height with the
// size y of the sprite
transform.localScale = new Vector3(
worldScreenWidth / sr.sprite.bounds.size.x,
worldScreenHeight / sr.sprite.bounds.size.y, 1);
}
} // class