Skip to content

Instantly share code, notes, and snippets.

@kazukitanaka0611
Created March 26, 2018 06:16
Show Gist options
  • Save kazukitanaka0611/cfddf1ebcf2bba8c2b9d19655f6b0b76 to your computer and use it in GitHub Desktop.
Save kazukitanaka0611/cfddf1ebcf2bba8c2b9d19655f6b0b76 to your computer and use it in GitHub Desktop.
Unity でマウスの位置に徐々に移動するスクリプト
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