앱 만들기/게임

유니티 - 스와이프 길이 구하기

나도 처음이야 2019. 2. 7.

유니티 - 스와이프 길이 구하기


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Car : MonoBehaviour

{

    Vector2 startPos;

    Vector2 endPos;

    float swipeLength;

    float speed;


    // Update is called once per frame

    void Update()

    {   // 스와이프 길이를 구한다.  

        // 마우스를 클릭했을때 혹은 폰 화면을 터치하면.

        if (Input.GetMouseButtonDown(0))

        {

            this.startPos = Input.mousePosition;


        }else if (Input.GetMouseButtonUp(0))

        {// 마우스 버튼에서 손가락을 떼었을때 좌표.


            this.endPos = Input.mousePosition;

            swipeLength = endPos.x - startPos.x;

            this.speed = swipeLength/500.0f;            

        }

   


  // 오브젝트 좌표점 이동하기. 

        transform.Translate(this.speed, 0, 0);

 // 점점 속도를 줄어들게 하기.

        this.speed *= 0.98f;


    }

}



반응형

댓글