[학원 Unity]/[게임 클라이언트 프로그래밍]
자동차 스와이프로 움직여 보기
롤링페이퍼
2024. 8. 20. 09:42
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
public class CarController : MonoBehaviour
{
private float CarMoveSpeed;
private Vector3 a;
private Vector3 b;
float speed = 0;
Vector2 startPos;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//스와이프 길이를 구한다
if(Input.GetMouseButtonDown(0))
{
// 마우스를 클릭한 좌표
this.startPos = Input.mousePosition;
}
else if(Input.GetMouseButtonUp(0))
{
// 마우스 버튼에서 손가락을 때었을 때 좌표
Vector2 endPos = Input.mousePosition;
float swipeLength = (endPos.x = this.startPos.x);
// 스와이프 길이를 처음 속도로 변경한다
this.speed = swipeLength / 500.0f;
}
transform.Translate(this.speed, 0, 0);
this.speed *= 0.98f;
}
}