본문 바로가기
tips/자주쓰는 C# 스크립트

유니티 RectTransform 좌표 이동

by 디지털 수공업자 2020. 12. 30.
반응형

offsetMin은 화면의 좌측 하단 기준, offsetMax는 화면의 우측 상단 기준으로 떨어진 값을 지정.

 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

    public class Test : MonoBehaviour {

        RectTransform rt ;

        public void RightSide() {

            // 화면 밖 오른쪽에 붙이기
            rt.offsetMin = new Vector2(Screen.width, 0f) ;
            rt.offsetMax = new Vector2(Screen.width, 0f) ;

        }

        public void LeftSide() {

            // 화면 밖 왼쪽에 붙이기
            rt.offsetMin = new Vector2(Screen.width * -1, 0f) ;
            rt.offsetMax = new Vector2(Screen.width * -1, 0f) ;

        }

        public void BottomSide() {

            // 화면 밖 아래쪽에 붙이기
            rt.offsetMin = new Vector2(0f, Screen.height * -1) ;
            rt.offsetMax = new Vector2(0f, Screen.height * -1) ;

        }

        public void TopSide() {

            // 화면 밖 위쪽에 붙이기
            rt.offsetMin = new Vector2(0f, Screen.height) ;
            rt.offsetMax = new Vector2(0f, Screen.height) ;

        }

    }

}

유니티 2D 애니메이션 : https://boxwitch.tistory.com/16
애드몹, 구글 플레이 서비스 유니티 플러그인 : https://boxwitch.tistory.com/29
유니티 포스트 프로세싱 적용 : https://boxwitch.tistory.com/64
DateTime을 string으로 : https://boxwitch.tistory.com/82

반응형

댓글