Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Component()方法在脚本附加到的对象上搜索(在您的示例中)文本组件_C#_Unity3d - Fatal编程技术网

C# Component()方法在脚本附加到的对象上搜索(在您的示例中)文本组件

C# Component()方法在脚本附加到的对象上搜索(在您的示例中)文本组件,c#,unity3d,C#,Unity3d,希望这有帮助! (哦,别忘了从您放置脚本的另一个对象中删除脚本,以防出现问题。否则您仍然会出错)no\u lives=GetComponent()似乎不起作用您确定Start()在Update之前被调用,并且GetComponent实际上正在将值设置为no\u lives?另外,lifes\u n需要转换为字符串lifes\u n.ToString()+“x”no\u lifes=GetComponent()似乎不起作用您确定在Update之前调用了Start(),并且GetComponent实

希望这有帮助!
(哦,别忘了从您放置脚本的另一个对象中删除脚本,以防出现问题。否则您仍然会出错)

no\u lives=GetComponent()
似乎不起作用您确定
Start()
Update
之前被调用,并且GetComponent实际上正在将值设置为
no\u lives
?另外,
lifes\u n
需要转换为字符串
lifes\u n.ToString()+“x”
no\u lifes=GetComponent()
似乎不起作用您确定在
Update
之前调用了
Start()
,并且GetComponent实际上正在将值设置为
no\u lifes
?此外,还需要将
lifes\n
转换为字符串
lifes\n.ToString()+“x”
文本和脚本都附加到同一对象,文本和脚本都附加到同一对象
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class level1_script : MonoBehaviour {

    public Text no_lives;

    // Use this for initialization
    void Start () {
        no_lives = GetComponent<Text>();
    }

    // Update is called once per frame
    void Update () {
        int lives_n = gamemanager.lives_f ();
        Debug.Log (lives_n);
        no_lives.text = lives_n + " x";
    }
}
void Update () {
    int lives_n = gamemanager.lives_f ();
    Debug.Log (lives_n);
    if(no_lives != null) {
        no_lives.text = string.Format("{0} x", lives_n);
    }
}
no_lives = GameObject.Find("MyText").GetComponent<Text>‌​()