32 lines
		
	
	
		
			782 B
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			32 lines
		
	
	
		
			782 B
		
	
	
	
		
			C#
		
	
	
	
|  | using UnityEngine; | |||
|  | using UnityEngine.UI; | |||
|  | 
 | |||
|  | [RequireComponent(typeof(RawImage))] | |||
|  | public class ImageScroller : MonoBehaviour { | |||
|  | 
 | |||
|  |     [SerializeField] | |||
|  |     private float speedX = default; | |||
|  |     [SerializeField] | |||
|  |     private float speedY = default; | |||
|  |     [SerializeField] | |||
|  |     private bool isStretchWidth = false; | |||
|  | 
 | |||
|  |     private RawImage rawImage; | |||
|  |     private Rect rect; | |||
|  | 
 | |||
|  |     void Awake(){ | |||
|  |         rawImage = GetComponent<RawImage>(); | |||
|  |         rect = rawImage.uvRect; | |||
|  | 
 | |||
|  |         if(isStretchWidth){ | |||
|  |             rect.width = rect.width * ((float)Screen.width / (float)Screen.height) / (9.0f / 16.0f); | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     void LateUpdate(){ | |||
|  |         rect.x += speedX * Time.deltaTime; | |||
|  |         rect.y += speedY * Time.deltaTime; | |||
|  |         rawImage.uvRect = rect; | |||
|  |     } | |||
|  | } |