【问题标题】:Property or indexer cannot be used in this context - Error in Unity v2019.3.4f1在此上下文中不能使用属性或索引器 - Unity v2019.3.4f1 中的错误
【发布时间】:2020-03-29 12:27:42
【问题描述】:

当我在文本上的z axis 上编写根据距离显示分数的代码时,它会显示此消息。 我写了一行:

scoreText.text = player.position.z.toString("0");

调试时的错误是:

The property or indexer 'TextInputBaseField<string>.text' cannot be used in this context because the set accessor is inaccessible [Assembly-CSharp]

请帮帮我,我在互联网上都有。 问候。

【问题讨论】:

    标签: c# unity3d game-development


    【解决方案1】:

    我敢打赌你使用了错误的 UI 元素。

    从第 4 行更改

    using UnityEngine.UIElements;
    

    using UnityEngine.UI;
    

    然后将scoreText的类型更改为Text,所以第8行将是:

    public Text scoreText;
    

    别忘了在编辑器中分配Text

    但如果我错了,而您使用的是正确的UIElements

    改变一下

    scoreText.text
    

    scoreText.value
    

    【讨论】:

    • @ARK69 在你完成第一个变体之后到底发生了什么?
    【解决方案2】:

    问题不大,只是我的编辑器的问题。我正在使用 Visual Studio Code,它在 1.1.4 版本中反复出现问题,我只需要将其降级到 1.1.3 版本。 如果其他人有这个问题,也可以这样做。 问候。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 2021-09-02
      • 1970-01-01
      相关资源
      最近更新 更多