我可以從腳本訪問該對象,但是我想直接更改腳本中的對象的值,這不是允許我。這裏是我的主要腳本紙條:C#腳本(子對象)不允許我在另一個腳本(這是父對象)訪問團結
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using RTS;
public class QuestionMenu : MonoBehaviour {
public struct Question{
public string questionText;
public string answer;
public string solution1;
public string solution2;
public string solution3;
}
//public void QuestionObject(string QuestionText, string answer, string solution1, string solution2, string solution3){
//Debug.Log ("lol");
//}
public Question QuestionObject = new Question();
Canvas canvas;
public UserInput Player;
public Text QuestionText;
public Text Button1;
// Use this for initialization
void Start() {
canvas = GetComponent<Canvas>();
canvas.enabled = false;
ResourceManager.QuestionMenuOpen = false;
//instruction = GetComponent<Text>();
//Debug.Log (QuestionText);
Button1.text = "Crazy";
QuestionText.text = "Yo Bro";
}
// Update is called once per frame
void Update() {
////Debug.Log (QuestionObject.questionText);
if(ResourceManager.QuestionMenuOpen == true){
//QuestionObject.questionText = "bloo";
Pause();
//QuestionText.text = "Question 1) Differentiate 3x\u2074 + 2x.";
//Button1.text = "12x\u00B3 + 2";
}
}
public void Pause(){
canvas.enabled = true;
Player.enabled = false;
Time.timeScale = 0.0f;
Cursor.visible = true;
//QuestionObject = Questions.QuestionObject;
Debug.Log (QuestionObject.questionText);
QuestionText.text = QuestionObject.questionText;
//ResourceManager.QuestionMenuOpen = true;
}
void Resume(){
Cursor.visible = false;
canvas.enabled = false;
Player.enabled = true;
Time.timeScale = 1.0f;
ResourceManager.QuestionMenuOpen = false;
}
}
這裏是我的腳本的腳本:
using UnityEngine;
using System.Collections;
public class QuestionScript : MonoBehaviour {
// Use this for initialization
void Start() {
QuestionMenu.QuestionObject.answer = "asdf";
}
// Update is called once per frame
void Update() {
}
}
編輯:我想從上面這裏顯示的紙條訪問對象QuestionObject是屏幕遊戲對象的截圖,連有兩個腳本
? – LumbusterTick
是的 - 我想改變稱爲QuestionObject的gameObject中的值(在結構後立即定義) – Nightshade