3 回答
TA貢獻2003條經驗 獲得超2個贊
publicprivate.
public class ScriptA : MonoBehaviour{
public int playerScore = 0;
void Start()
{
}
public void doSomething()
{
}}playerScoreScriptAScriptBGameObject.FindGetComponent
public class ScriptB : MonoBehaviour{
ScriptA scriptInstance = null;
void Start()
{
GameObject tempObj = GameObject.Find("NameOfGameObjectScriptAIsAttachedTo");
scriptInstance = tempObj.GetComponent<ScriptA>();
//Access playerScore variable from ScriptA
scriptInstance.playerScore = 5;
//Call doSomething() function from ScriptA
scriptInstance.doSomething();
}}TA貢獻1860條經驗 獲得超8個贊
HealthEnemy_StatsComponentPlayer_StatsStart
DestroyEnemy_Stats
TA貢獻2065條經驗 獲得超14個贊
gameObject.GetComponent<Character_Stats>()Start()
GetComponentDictionary<GameObject, Enemy_Stats>
添加回答
舉報
