this.transform.Rotate(0, 0, rotateAngle); 를 getmousebottondown 안에 넣으면 잘 날라가지만 돌아가질 않고
밖에다가 넣으면 원처럼 크게 돌아간다. 그리고 마우스를 누르면 돌아가기 시작하는게 아니라 시작부터 돌아감
그리고 자꾸 실행하면 버튼을 누르지 않아도 회전을 하는데 코드에 문제가 없어서 왜그런가 했더니 처음에 맴버변수를 public으로 만들었는데 거기에서 10으로 되어있어서 계속 돌아가던것이었다.
또한 큰 원처럼 돌아가는 것은 space.world를 코드에 추가함으로서 해결하였다.
근데 왜 rotate가 아니라 translate에다가 space.world를 써야하는지 잘 이해가 되지 않는다.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShurikenController : MonoBehaviour
{
private Vector3 startPos;
private Vector3 endPos;
public float moveSpeed=0;
public float rotateAngle=0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("down");
this.startPos = Input.mousePosition;
rotateAngle = 10;
}
else if (Input.GetMouseButtonUp(0))
{
Debug.Log("up");
this.endPos = Input.mousePosition;
float swipeLength = endPos.y - startPos.y;
this.moveSpeed = swipeLength / 600f;
}
this.transform.Rotate(0, 0, rotateAngle);
this.transform.Translate(0, this.moveSpeed, 0,Space.World);
}
}

'유니티 기초' 카테고리의 다른 글
고양이 구름 (0) | 2023.08.02 |
---|---|
고양이 구름 올라가기 게임 (0) | 2023.08.02 |
고양의 체력을 적용하고 체력이 0이 되었을경우에 GameOver를 화면에 출력해라! (0) | 2023.08.02 |
고양이 범위 못벗어나게 하기 (0) | 2023.08.02 |
고양이 화살표 부딪히면 사라짐 (0) | 2023.08.01 |