【问题标题】:The left-hand side of an assignment作业的左侧
【发布时间】:2018-09-10 14:04:09
【问题描述】:

我正在统一制作游戏,并尝试制作一个 android 滑动控制系统。它与教程中的相同,但不知何故它为我返回错误 - “错误 CS0131 赋值的左侧必须是变量、属性或索引器”。我怎样才能使这段代码工作?

bool isDraging = false;
Vector2 startTouch, swipeDelta = Vector2.zero;

if (isDraging)
{
    if (Input.touches.Length > 0)
        swipeDelta = Input.touches[0].position = startTouch; 
    else if(Input.GetMouseButton(0))
        (Vector2)Input.mousePosition = startTouch = swipeDelta;    
}

【问题讨论】:

  • 如您所见from the docsmousePosition只读,因此您不能在else if 分支中分配给它。这让我印象深刻XY Problem,你到底想解决什么?可能有更好的方法。

标签: c# unity3d


【解决方案1】:

您的错误是您试图更改mousePosition。 Unity 游戏引擎无法更改mousePosition。为此,您需要使用system.windows.forms.cursor.position。为此,您需要将 windows.form.dll 添加到项目的程序集中。为此,请将 dll 下载到 Unity 资产文件夹并在代码开头添加:

using dllNamespace

注意 dllNamespace 是您的 dll 的命名空间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多