using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shurikenSwipe : MonoBehaviour
{
float moveSpeed = 0;
Vector3 startPos;
Vector3 endPos;
float damplingCoefficient = 0.98f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.LogFormat("Down: {0}", Input.mousePosition);
this.startPos = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(0))
{
Debug.LogFormat("Down: {0}", Input.mousePosition);
this.endPos = Input.mousePosition;
float swipeLength = endPos.y - startPos.y;
this.moveSpeed = swipeLength/1000;
}
this.transform.Translate(0, moveSpeed, 0, Space.World);
if (moveSpeed > 0)
{
this.transform.Rotate(0f, 0f, 10f);
}
moveSpeed *= damplingCoefficient;
}
}
startPos와 endPos변수에 마우스를 눌렀을때와 뗐을 때의 좌표를 저장해서 이동한 y축의 길이만큼 표창을 날리기로 했다.
수리검을 날렸을 때 오브젝트의 좌표계도 같이 돌면서 표창이 이상한 곳으로 날라갔지만 월드 좌표계를 사용하여 해결하였다.
'유니티 기초' 카테고리의 다른 글
유니티짱 마우스로 움직이기 (0) | 2023.08.04 |
---|---|
밤송이 던지기 (0) | 2023.08.04 |
유니티 애니메이션(점프) (0) | 2023.08.03 |
유니티 애니메이션 (0) | 2023.08.03 |
구름타는 고양이 (0) | 2023.08.02 |