Get it on Google Play


Wm뮤 :: UGui 관련

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2020. 5. 19. 21:34 Unity/C#

 

 

아래건 일정시간뒤 지정한 룸으로 이동하는 코드

 

 

근데 이따구로 짜지말고 코루틴으로 짜시길

 

 

 

슬라이더로 애니메이터 시간을 조정

1e+08은 100000000이고 1e-08은 0.00000001임

0으로 하면 플레이 시간이 무한대로 되니까 이렇게 한것, 그래도 190년동안 지켜봐야 애니메이션이 끝나니까 

일반적으론 지장없음, 그때쯤이면 유니티가 망할듯

rebind가 먼저오고 update가 나중에 와야함 여기서update는 해당시간에서 재생하겠다는 의미임

 

 

버튼을 누른거로 쳐줌

GetComponent<Button>().onClick.Invoke();

 

버튼에 리스터너 추가

 

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

public class Choice : MonoBehaviour
{

    public Button button;
    List<Button> buttonClones= new List<Button>();


    public string folderPath="/Spreadsheets";
    //public string[] filePaths;
    public void PressButton(string filePath)
    {
        Debug.Log($"PressButton({filePath})");
    }
    // Start is called before the first frame update
    void Start()
    {
        button.gameObject.SetActive(false);

        
        var filePaths = System.IO.Directory.GetFiles($"{Application.persistentDataPath + folderPath}");
        var fileNames = System.Array.ConvertAll(filePaths,x=> System.IO.Path.GetFileNameWithoutExtension(x));



        for (int i = buttonClones.Count; i < fileNames.Length; i++)
        {
            var gameObject = Instantiate(button.gameObject, button.transform.parent);
            gameObject.SetActive(true);
            gameObject.GetComponentInChildren<Text>().text= $"{fileNames[i]}";
            var filePath = filePaths[i];
            gameObject.GetComponent<Button>().onClick.AddListener(() => PressButton(filePath)); //직접참조하지 말고 지역변수를 만들어서 할당
            buttonClones.Add(gameObject.GetComponent<Button>());
        }
    }

    // Update is called once per frame
    void Update()
    {
    }
}

다른 버전

더보기
public static int selectWeaponIndex=0;
public GameObject selectButton;
 List<GameObject> selectButtons= new List<GameObject>();
// Start is called before the first frame update
void Start()
{
    var length = selectButton.GetComponentInChildren<WeaponSystem>().weapons.Length;
    for (int i = 0; i < length; i++)
    {
        var instant=Instantiate(selectButton, selectButton.transform.parent);
        instant.GetComponentInChildren<WeaponSystem>().weaponIndex = i;
        var index = i;
        instant.GetComponent<Button>().onClick.AddListener(() => PressButton(index)); //직접참조하지 말고 지역변수를 만들어서 할당
        selectButtons.Add(instant);
    }
    selectButton.SetActive(false);
}
public void PressButton(int index)
{
    selectWeaponIndex = index;
    Debug.Log($"PressButton({index})");
}

 

 

 

 

 

2행 grid layout group (열 column,행 row)

 

 

 

 

 

 

 

ugui에 3d 넣기

https://wmmu.tistory.com/entry/ugui%EC%97%90-3d-%EB%84%A3%EA%B8%B0

 

ugui에 3d 넣기

결과물 화면비율 아무리 바꿔도 잘 된다 가로기준이라는거만 빼면 좋음

wmmu.tistory.com

 

 

 

 

 

'Unity > C#' 카테고리의 다른 글

유니티 어트리뷰트  (0) 2020.05.19
안드로이드에서 뒤로가기 버튼을 누르면 종료됨  (0) 2020.05.19
2D용 LookatTarget  (0) 2020.05.19
posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입