본문 바로가기
✨ Club/C크루 게임 개발챌린지 | 유니티 2D (C#)

본선개발 - Unity15

by 정람지 2022. 9. 14.

그림은 내가 아빠 생일 프로그램에 썼던 그림

 

멘토님이 도와주셨던..

아주 부끄러운 실수를 한.. 스크롤링..


마우스이벤트 터치이벤트로 바꾸기

원래 코드 세이브해놓고

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

public class swipe_menu : MonoBehaviour
{
    public GameObject scrollbar;
    float scroll_pos =0;
    float[] pos;
    
    void Start(){   
    }
    void Update()
    {
        pos = new float[transform.childCount];
        float distance = 1f / (pos.Length -1f);
        for (int i = 0; i <pos.Length; i++) {
            pos [i] = distance * i;
        }
        if (Input.GetMouseButton(0)){
            scroll_pos = scrollbar.GetComponent<Scrollbar> ().value;
        }
        /* 없는게더자연스러운데..?
        else{
            for (int i = 0; i < pos.Length; i++){
                if (scroll_pos < pos[i] + (distance /2) && scroll_pos > pos[i] - (distance /2)) {
                    scrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp (scrollbar.GetComponent<Scrollbar>().value, pos[i], 0.1f);
                }
            }
        }
        */
        
        for (int i = 0; i < pos.Length; i++){
            if (scroll_pos< pos [i] + (distance /2) && scroll_pos > pos[i] - (distance /2)) {
                transform.GetChild (i).localScale = Vector2.Lerp (transform.GetChild(i).localScale, new Vector2(1f,1f),0.01f);
                for (int a = 0; a < pos.Length; a++){
                    if (a != i) {
                        transform.GetChild (a).localScale = Vector2.Lerp(transform.GetChild(a).localScale, new Vector2(0.7f,0.7f), 0.01f);
                    }
                }
            }
        }
    }
}

Input 클래스의 Touch 구조체

 

Input.GetMouseButton(0) 만 Input.GetTouch(0) 로 바꾸면 되는 것 같다!

(0)은 첫번째 손가락 터치만 가져온다는 뜻 

 

error CS0029: Cannot implicitly convert type 'UnityEngine.Touch' to 'bool' 

뭐지..

Input.GetMouseButton(0)는 bool 형이었나 보다.

 

유니티(UNITY) / 모바일 터치 코드 요약

유니티에 관심이 있다니 놀랍군요!! 모바일 스크린에서 터치를 인식하는 코딩을 간략하게 정리해 보았습니다. 1. 터치된 손가락 갯수 인식하기   // 손가락 터치가 1개 일때   if(Input.touchCount ==

blog.daum.net

 

 

근데 이걸 테스트해보려면..


모바일 연결해보기

저번과 저저번은 실패했지만..

재도전

 

모바일 빌드시, Input.GetTouch(0) 사용법 : argumentexception: index out of bounds 해결법

유니티 공부 노트 Touch Input 이용시 에러? 분명히 에디터에서는 마우스 클릭 입력으로 잘 동작했는데, 모바일로 빌드하니 제대로 작동을 하지 않아 원인을 파악하던 중, Input 관련에 문제가 있다

koreanfoodie.me

!!

 터치 자체가 없는데, Input 에서 Touch 의 첫번째 인덱스를 가져오려 해서 생긴 문제

 

연결 잭을 안 가져왔군

집에서 다시 해야겠다


클릭하면 카드정보 찍히게 하기

카드를 클릭했을 때 해당 카드의 정보를 가져다 써야 하므로

일단 해당 카드의 번호가 콘솔에 찍히게 해 보자

 

 

유니티 스크립트에서 버튼에 온클릭 리스너 추가하기(onClick.AddListener)

유니티 스크립트에서 버튼에 온클릭 리스너 추가하기(onClick.AddListener) 스크립트에서 버튼에 온클릭 이벤트 리스너 추가하는 방법 1)일반적으로 버튼 컴포넌트에서 직접 게임 오브젝트를 참조하

learnandcreate.tistory.com

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

public class Buttonclick : MonoBehaviour
{
    public Button btn1, btn2, btn3, btn4, btn5, btn6, btn7 ;

    void Start()
    {
        btn1.onClick.AddListener(btn1print);
        btn2.onClick.AddListener(btn2print);
        btn3.onClick.AddListener(btn3print);
        btn4.onClick.AddListener(btn4print);
        btn5.onClick.AddListener(btn5print);
        btn6.onClick.AddListener(btn6print);
        btn7.onClick.AddListener(btn7print);
    }
    void btn1print()
    {
        Debug.Log("0");
    }
    void btn2print()
    {
        Debug.Log("1");
    }
    void btn3print()
    {
        Debug.Log("2");
    }
    void btn4print()
    {
        Debug.Log("3");
    }
    void btn5print()
    {
        Debug.Log("4");
    }
    void btn6print()
    {
        Debug.Log("+");
    }
    void btn7print()
    {
        Debug.Log("-");
    }
}

챱챱

버튼UI는 모바일이랑 컴 터치 모두 기본설정이 되어있나 보다!


SVM 탐구하기

안 되는데..

계속 안 되면 그냥

수연이가 한 것처럼 각자 파일 보내서

한명이 합쳐야 할 것 같다.

 

 

'✨ Club > C크루 게임 개발챌린지 | 유니티 2D (C#)' 카테고리의 다른 글

본선개발 - Unity 17  (0) 2022.09.16
본선개발 - Unity 16  (0) 2022.09.14
본선개발 - Unity 14  (0) 2022.09.12
본선공부 - Unity 13  (0) 2022.09.12
본선개발 - Unity 12  (0) 2022.09.11