属性 或索引器无法在此上下文中使用 - Unity v2019.3.4f1 中的错误
Property or indexer cannot be used in this context - Error in Unity v2019.3.4f1
当我在文本 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]
请大家帮帮我,我都在网上。
问候。
我打赌你用错了 UI 元素。
从
更改第 4 行
using UnityEngine.UIElements;
至
using UnityEngine.UI;
然后将 scoreText
的类型更改为 Text
,因此第 8 行将是:
public Text scoreText;
不要忘记在编辑器中分配 Text
!
但是如果我错了,而你使用的是正确的UIElements
只是改变
scoreText.text
至
scoreText.value
问题不大,只是我的编辑 problem.I 正在使用 Visual Studio 代码,该代码在 1.1.4 版中反复出现问题,我不得不将其降级到 1.1.3 版.
如果其他人遇到此问题,请执行相同的操作。
问候。
当我在文本 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]
请大家帮帮我,我都在网上。 问候。
我打赌你用错了 UI 元素。
从
更改第 4 行using UnityEngine.UIElements;
至
using UnityEngine.UI;
然后将 scoreText
的类型更改为 Text
,因此第 8 行将是:
public Text scoreText;
不要忘记在编辑器中分配 Text
!
但是如果我错了,而你使用的是正确的UIElements
只是改变
scoreText.text
至
scoreText.value
问题不大,只是我的编辑 problem.I 正在使用 Visual Studio 代码,该代码在 1.1.4 版中反复出现问题,我不得不将其降级到 1.1.3 版. 如果其他人遇到此问题,请执行相同的操作。 问候。