简体   繁体   English

无法将类型`string'隐式转换为`UnityEngine.GUIText'

[英]Cannot implicitly convert type `string' to `UnityEngine.GUIText'

I am making a game in Unity and I want to display the lives the player has left on the screen. 我在Unity制作游戏,我希望显示玩家在屏幕上留下的生命。 I keep getting the error: "Cannot implicitly convert type `string' to UnityEngine.GUIText" in Unity when I compile the code shown below. 我不断收到错误:“当我编译下面显示的代码时,不能在Unity中隐式转换类型`string'到UnityEngine.GUIText”。 I have seen the Update function in the Message class work seamlessly exactly like that in a tutorial so I don't know what my problem is. 我已经看到Message类中的Update函数与教程中的Update函数完全一样,所以我不知道我的问题是什么。

public class GameManager : MonoBehaviour {

    public static int lives = 3;
}

//

public class Message : MonoBehaviour
{

    public Text scoreText;

    void Update()
    {
        scoreText.text = "Lives: " + GameManager.lives.ToString();
    }
}

Did you include: using UnityEngine.UI; 你有没有包括: using UnityEngine.UI; on top of your code? 在你的代码之上?

You can double click on an Error to see where it is coming from. 您可以双击错误以查看它的来源。 You get informations about the name of the script and the line where the error is coming from. 你得到有关该脚本的名称和错误是来自该的信息。 Hope it helps. 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型字符串隐式转换为“UnityEngine.UI.Text” - Cannot implicitly convert type string to `UnityEngine.UI.Text' 无法将类型“UnityEngine.AudioClip”隐式转换为“UnityEngine.AudioSource” - Cannot implicitly convert type 'UnityEngine.AudioClip' to 'UnityEngine.AudioSource' 无法隐式转换类型'UnityEngine.Vector2?'到'UnityEngine.Vector2' - Cannot implicitly convert type 'UnityEngine.Vector2?' to 'UnityEngine.Vector2' 无法将类型'UnityEngine.ScriptableObject'隐式转换为'T' - Cannot implicitly convert type `UnityEngine.ScriptableObject' to `T' 无法将类型int'隐式转换为unityengine.vector3' - cannot implicitly convert type int' to unityengine.vector3' 如何修复“无法将类型'void'隐式转换为'UnityEngine.AsyncOperation”? - How to fix "Cannot implicitly convert type 'void' to 'UnityEngine.AsyncOperation"? 无法将类型“UnityEngine.GameObject”隐式转换为“GameObject” - Cannot implicitly convert type 'UnityEngine.GameObject' to 'GameObject' 无法将类型“float”隐式转换为“UnityEngine.Quaternion” - Cannot implicitly convert type 'float' to 'UnityEngine.Quaternion' c#无法将类型“布尔”隐式转换为“ UnityEngine.CursorLockMode” - c# Cannot implicitly convert type 'bool' to 'UnityEngine.CursorLockMode' 无法将类型'bool'隐式转换为'UnityEngine.RaycastHit' - Cannot implicitly convert type `bool' to `UnityEngine.RaycastHit'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM