using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class shurikenController : MonoBehaviour
{
    float moveSpeed = 0;
    float rotationSpeed = 1000f;  // 회전 속도
    float dampingCoefficient = 0.96f;   //감쇠계수 

    private Vector3 startPos;  //down 했을때 위치 

    // 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("Up: {0}", Input.mousePosition);

            Vector3 endPos = Input.mousePosition;

            float swipeLength = endPos.y - startPos.y;
            Debug.LogFormat("swipeLength: {0}", swipeLength);  //화면좌표에서 두점사이의 거리 

            //화면좌표계에서의 두점사이의 거리에 비례해서 이동 좌표계가 안맞아서 어림잡아 500정도 나눠줬다 
            this.moveSpeed = swipeLength / 500f;

            Debug.LogFormat("moveSpeed: {0}", this.moveSpeed);
        }

        //x축으로 moveSpeed만큼 매 프레임마다 이동 (World: 글로벌 좌표계)
        this.transform.Translate(0, this.moveSpeed, 0,Space.World);
        //감쇠 매프레임마다 0.95f를 moveSpeed에 곱해서 적용 -> 점점 줄이겠다 -> 0.00xx 0과 비슷해짐 
        this.moveSpeed *= this.dampingCoefficient;

        // Z축을 중심으로 rotationSpeed만큼 매 프레임마다 회전 (World: 글로벌 좌표계)
        this.transform.Rotate(0, 0, this.rotationSpeed * Time.deltaTime, Space.World);
    }
}

 

 

+ Recent posts