~ 2D mouse click on unity ~

| unity | No Comments

在要hit test的gameobject內加入Box Collider 2D

01

 // Update is called once per frame
    void Update() {
        if (Input.GetMouseButtonDown(0))
        {
            print("mousedown");

            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            if (hit.collider != null)
            {
                print(hit.collider.gameObject.name);
            }
        }
    }

 

トラックバック

このブログ記事に対するトラックバックURL:

コメント & トラックバック

No comments yet.

Comment feed

コメントする

Smiley face

April 2024
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930