Skip to content

Instantly share code, notes, and snippets.

@adash333
Created August 18, 2019 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adash333/a7fc96646acbdd309b9872b80349e1c6 to your computer and use it in GitHub Desktop.
Save adash333/a7fc96646acbdd309b9872b80349e1c6 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
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;
// 効果音再生
GetComponent<AudioSource>().Play();
}
transform.Translate(this.speed, 0, 0);
this.speed *= 0.98f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment