[英]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.