yyl
2025-06-09 b9751b2f076ee050fe5b685e91ae4fc4469b1015
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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]);
        }
    }
 
}