티스토리 뷰
#Input.etMouseButtonDown(0) 메서드
#(0) 마우스 좌클릭 (1)우클릭
#if문에 조건으로 넣으면 작동하게 만들어보자
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoulettController : MonoBehaviour
{
private float rotSpeed = 0;
public float attenuation = 0.96f; //회전속도. 반복해서 곱하면 점점 감속
// Start is called before the first frame update
void Start()
{
Debug.LogFormat("클릭하면 회전합니다");
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0)) //0은 마우스 좌 클릭
{
this.rotSpeed = 10f;
}
//게임오브잭트를 회전하는 방법
//회전은 Transform이 관리함
this.transform.Rotate(0, 0, this.rotSpeed); //transform.Rotate 회전
//감속시키기 *0.96f
this.rotSpeed = this.rotSpeed * this.attenuation;
Debug.LogFormat("speed:{0}",this.rotSpeed);
if(this.rotSpeed<0.01f) //float는 정확도가 떨어짐으로 0으로 만들어주자
{
this.rotSpeed = 0;
}
}
}
#rotSpeed*0,96 을 계속 곱해주면 천천히 감소한다
#완전히 0으로 감소할수는 없으니 0.0f가 된다면 0으로 만들어주자(float는 정확도가 떨어지는구나..)
'게임클라이언트 프로그래밍 > Unity' 카테고리의 다른 글
교제 5장 복습 (1) | 2023.01.31 |
---|---|
CatEscape (0) | 2023.01.30 |
회전 수리검 (0) | 2023.01.30 |
캐릭터 이동시키기 (0) | 2023.01.30 |
Unity 스크립트 작성 (0) | 2023.01.27 |