Created
March 26, 2018 06:16
-
-
Save kazukitanaka0611/cfddf1ebcf2bba8c2b9d19655f6b0b76 to your computer and use it in GitHub Desktop.
Unity でマウスの位置に徐々に移動するスクリプト
This file contains hidden or 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 TouchMove : MonoBehaviour { | |
[SerializeField] private GameObject cube; | |
[SerializeField]private float speed = 2.0f; | |
// Update is called once per frame | |
void Update () | |
{ | |
if(Input.GetMouseButton(0)) | |
{ | |
Debug.Log("mouse douwn"); | |
Vector3 pos = Input.mousePosition; | |
pos.z = 10.0f; | |
Vector3 worldPos = Camera.main.ScreenToWorldPoint(pos); | |
cube.transform.position = Vector3.MoveTowards(cube.transform.position, worldPos, speed *Time.deltaTime); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment