본문 바로가기

유니티(Unity)

커서 잠금 시 스크롤 뷰 마우스 휠 사용 안됨. 해결방법

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class MouseWheel_DepartmentScene : MonoBehaviour
{
    public GameObject content;
    public float speed;
    private float mouseScroll;
    RectTransform transformContent;
 
    // 스크롤뷰의 content부분을 마우스 휠로 내리게 위해서 만듬.
    //Cursor.lockState = CursorLockMode.Locked 되면 즉, 마우스 포인트가 고정되면 스크롤 뷰에 내장된 기능인 마우스휠 컨트롤을
    //사용할 수가 없음. 그래서 아래와 같이 따로 스크립트를 작성해주어야함.
 
    void Start()
    {
        transformContent = content.GetComponent<RectTransform>(); 
    }
    void Update()
    {
        mouseScroll = Input.GetAxis("Mouse ScrollWheel");
        transformContent.anchoredPosition -= new Vector2(0, speed * mouseScroll);
    }
}
cs

 

'유니티(Unity)' 카테고리의 다른 글

Unity 동기 비동기 async await  (0) 2022.10.26
오브젝트 정보 UI 에 표시하기  (0) 2022.10.25
Unity Relay서버  (0) 2022.10.25
namespace  (0) 2022.10.10
포스트 프로세싱(Post-Processing)이 적용안된다면?URP 2021.3  (0) 2022.09.04