0
嗨,我是Unity新手,發現很難適應事物的概念。我的問題是,我有一個方法返回一個字符串,另一個方法在不同的類中調用方法來獲取該字符串,我嘗試實現這個字符串永遠不會從其他類訪問。訪問來自不同班級團結的數據
這裏是返回字符串
public string getString(){
string hi = "why hello";
return hi;
}
這裏是它打印按鈕時按下
void OnMouseUp(){
firstScript log = (firstScript)FindObjectOfType(typeof(firstScript));
string hello = log.getString()
print (hello);
}