12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

マウスカーソルの位置にオブジェクトを置きたい時

Posted at

こんな感じで、Cubeをカーソルを追いかけるように移動させたい時は

a.gif

こんなScriptを書いてCubeに貼ります。

MouseScript.cs
using UnityEngine;
using System.Collections;

public class MouseScript : MonoBehaviour {

	Vector3 screenPoint;
	
	// Update is called once per frame
	void Update () {
		this.screenPoint = Camera.main.WorldToScreenPoint(transform.position);
		Vector3 a = new Vector3 (Input.mousePosition.x,Input.mousePosition.y,screenPoint.z);
		transform.position = Camera.main.ScreenToWorldPoint (a);
	}
}


12
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?