0

我正在尝试在 raylib_cs 中创建一个 UI 按钮,但我似乎找不到哪里出错了,有没有人可以将我发送到教程帮助解决问题?

public bool CanClick()
    {
        Vector2 mousePos = new Vector2(Raylib.GetMousePosition().X, Raylib.GetMousePosition().Y);           // Get the position of the mouse
        if (mousePos.X >= GlobalPosition.X && mousePos.X <= (GlobalPosition.X + ButtonWidth))
        {
            if (mousePos.Y >= GlobalPosition.Y && mousePos.Y <= GlobalPosition.Y + ButtonHeight)
            {
                return true;
            }
        }

        return false;
    }

    public void DetectClick()
    {
        if(Raylib.IsMouseButtonDown(MouseButton.MOUSE_LEFT_BUTTON))
        {
            if(CanClick())
            {
                Console.WriteLine(objectName + " Pos: " + GlobalPosition.ToString());
                if (onClickAction != null)
                {
                    onClickAction();
                }
            }
        }
    }
4

0 回答 0