[유니티 입문 강좌] part11 UI의 기본

kkily·2021년 11월 21일
0

UI

hierarchy에 UI > canvas 만들어주고 canvas 아래에 panel 만들어줌

  • text 만들어준 상태

텍스트 size를 키우면 안보이는데 글씨 크기가 들어갈 수 있는 공간보다 커서 그런 것. ->

로 변경하면 됨

또는 best fit을 선택하면 여유공간안에 텍스트 사이즈를 자동으로 맞춰줌

raycast target을 해제하면 글자 뒤에 있는 버튼도 눌러짐

  • Image 만들어준 상태

체력을 줄게 할 때

이렇게 설정해두고 fill amount를 줄이면 됨

  • Button 만든 상태
    button은 image 필드와 text 필드 둘 다 있음

interactable:반응해서 상호작용 하겠느냐
transition: 마우스 갖다댈 때 변화
on click: 클릭했을 때 실행할 함수

  • 변경버튼 눌렀을 시 변화
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test_chap11 : MonoBehaviour{

[SerializeField] private Text txt_name;
[SerializeField] private Image img_name;

    // Start is called before the first frame update
    public void Change()
    {
        txt_name.text="변경됨";
        img_name.fillAmount=0.5f;
        
    }
    
    
}

<전체 모습>

Button에 함수 추가

왼쪽 아래 버튼이 빙글 돎

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

public class Test_chap11 : MonoBehaviour{

[SerializeField] private Text txt_name;
[SerializeField] private Image img_name;
[SerializeField] private Sprite sprite;

private bool isCoolTime=false;
private float currentTime=5f;
private float delayTime=5f;

void update(){
    img_name.color=Color.red; //색 변화 가능
    // img_name.sprite= 어쩌구 //sprite 변화 가능

    //색 투명하게
    Color color - img_name.color;
    color.a=0f;
    img_name.color=color;

    if(isCoolTime){
        currentTime-=Time.deltaTime;
        img_name.fillAmount=currentTime/delayTime; //버튼이 빙글빙글 돌게됨

        if(currentTime<=0){ //다시 누르면 다시 돌 수 있게
            isCoolTime=false;
            currentTime=delayTime;
            img_name.fillAmount=currentTime;
        }
    }
}


    // Start is called before the first frame update
    public void Change()
    {
        txt_name.text="변경됨";
        isCoolTime=true;
        
    }
    
    
}

    

profile
낄리의 개발 블로그╰(*°▽°*)╯

0개의 댓글