using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class RandomImage : MonoBehaviour { [SerializeField] string[] m_ImageKeys; [SerializeField] Image m_Image; private void OnEnable() { var screenAspect = (Screen.width / (float)Screen.height) / (Constants.DESIGN_RESOLUTION.x / Constants.DESIGN_RESOLUTION.y); this.transform.localScale = Mathf.Clamp(screenAspect, 1f, 2f) * Vector3.one; if (m_ImageKeys != null && m_ImageKeys.Length > 0) { var index = Random.Range(0, m_ImageKeys.Length); m_Image.SetSprite(m_ImageKeys[index]); } } }