![]() |
![]() |
플랫폼: PC
기능: 마우스 좌 / 우 클릭을 하면 룰렛이 회전함
- X좌표(붉은 화살표)의 화살표 방향은 + 반대는 -로 돌아가는 방향에 따라 콘솔 좌표 값이 변화한다.
* void Updata() { } - 프레임마다~ 업데이트 되는 메서드 작성 1. 화면 조작 감지 : 마우스 클릭 bool isDown = Input.GetMouseButtonDown(0); //0 왼, 1오 bool isRihgtDown = Input.GetMouseButtonDown(1); //0 왼, 1오 bool isMiddleDown = Input.GetMouseButtonDown(2); // 2(가운데=휠?) -bool 타입으로 클릭 시, true를 반환한다. -Input.GetMouseButtonDown(2)는 가운데라길래 휠인줄 알고 넣어봤는데 아닌 듯, 시작하면 도는 오류가 생겨서 주석 처리함 2. 회전 this.transform.Rotate(0, 0, rotationSpeed); // (x,y,z) - z 좌표에 변수를 받아 적용한다. 3. 디버그 컬러 코드 - Debug.Log($"<color=red>왼쪽을 눌렀습니다.</color>"); |
- RouletteControler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RouletteControler : MonoBehaviour
{
private float rotationSpeed = 0; // 룰렛 속도 제어 변수
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//1. 화면 감지
bool isDown = Input.GetMouseButtonDown(0); //0 왼, 1오, 3휠
bool isRihgtDown = Input.GetMouseButtonDown(1); //0 왼, 1오, 2휠
bool isMiddleDown = Input.GetMouseButtonDown(2); //0 왼, 1오, 2휠
if (isDown)
{
Debug.Log($"<color=red>왼쪽을 눌렀습니다.</color>");
rotationSpeed += 100; //3.누르면 +로 회전 시키기
}
else if(isRihgtDown)
{
Debug.Log($"<color=red>오른쪽을 눌렀습니다.</color>");
rotationSpeed -= 100; //3.누르면 -로 회전 시키기
}
//else
//{
// Debug.Log("휠을 눌렀습니다.");
// rotationSpeed += 100; //3.누르면 회전 시키기
//}
//2. 회전하기
this.transform.Rotate(0, 0, rotationSpeed);
//4.속도 줄이기
rotationSpeed *= 0.96f;
Debug.Log(rotationSpeed);
}
}
'게임 클라이언트 프로그래밍' 카테고리의 다른 글
게임 오브젝트에 연결된 클래스에 접근 하는 방법: Inspector 직접 연결 / 접근_한정자 게임오브젝트_타입 변수명; (0) | 2024.08.21 |
---|---|
게임 오브젝트에 연결된 클래스에 접근 하는 방법 GameObject.Find(); (0) | 2024.08.21 |
게임 오브젝트에 연결된 클래스에 접근 하는 방법: FindObjectOfType<T>(); (0) | 2024.08.21 |
Vector(x,y,z) (1) | 2024.08.20 |
라이프 사이클 = 이벤트 함수 실행 순서 (1) | 2024.08.19 |