Created
August 18, 2019 13:58
-
-
Save adash333/a7fc96646acbdd309b9872b80349e1c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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