예제 #1
0
    private void Update()
    {
        //首先判断是否点击了鼠标左键
        bool leftClick  = Input.GetMouseButtonDown(0);
        bool rightClick = Input.GetMouseButtonDown(1);

        if (CurrentTurn == TurnType.WaitForFinish && (leftClick || rightClick))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            var hit = Physics2D.Raycast(ray.origin, ray.direction);
            Debug.DrawRay(ray.origin, ray.direction, Color.red, 1);
            if (hit.transform != null)
            {
                AddText("检测到碰撞,碰撞体位置", hit.transform.position);
                if (leftClick)
                {
                    CellCollector.Open(hit.collider.gameObject);
                }
                if (rightClick)
                {
                    CellCollector.Mark(hit.collider.gameObject);
                }
            }
            else
            {
                AddText("未检测到碰撞,起始位置", ray.direction);
                AddText("未检测到碰撞,当前鼠标位置", ray.origin);
            }
        }
    }