2
3

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.

unity > マウス位置の取得

Last updated at Posted at 2015-07-30

https://unity3d.com/learn/tutorials/modules/intermediate/scripting/coroutines?playlist=17117
の3:15のコード

...

void OnMouseDown () 
{
   Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
   RaycastHit hit;
   
   Physics.Raycast(ray, out hit);

   if(hit.collider.gameObject == gameObject)
   {
      coroutineScript.Target = hit.point;
   }
}

マウスカーソルの位置にgameObjectが移動していた。

実際に試した所、hit.pointはVector3の情報を持っているのがわかった。

上記のスクリプトをPlaneにアタッチした場合、Planeの一部にマウスカーソルが置かれた時にhitとみなされ、その座標 hit.point が取得できた。

マウスクリックの有無は無関係だった。


2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?