📌  相关文章
📜  unity 知道游戏对象何时被按下 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:55.240000             🧑  作者: Mango

代码示例1
void Update () {
         if (Input.GetMouseButtonDown(0)) {
             CastRay();
         }       
     }

     void CastRay() {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);
         if (hit.collider !=null) {
             Debug.Log (hit.collider.gameObject.name);
     }