0
개체를 인스턴스화하려고 시도하고 인스턴스화 할 때 uiManager
변수의 개체를 uiManager
spawnPlayer
의 변수로 인스턴스화하려고합니다.개체를 인스턴스화하고 변수를 설정하면 개체가 단일체로 작동하지 않습니다. C#
게임을하고 일시 중지 한 다음 인스턴스화 된 개체를 보면 변수가 설정되지 않습니다.
코드가 있습니다.
using UnityEngine;
using System.Collections;
public class playerSpawner : MonoBehaviour {
public GameObject[] cars;
public uiManager ui;
int carSpawned;
void Start()
{
spawn();
}
void spawn()
{
Instantiate (cars [carPicController.next], transform.position, transform.rotation);
carPicController.next = carSpawned;
Debug.Log ("player spawned");
setuiManager();
}
void setuiManager()
{
//get the thing component on your instantiated object
uiManager ui = cars [carSpawned].GetComponent<uiManager>();
//set a member variable (must be PUBLIC)
ui = ui;
}
}
그냥 표준적인 일로, 내 모든 공용 메서드와 변수는 대문자로 시작하고 모든 개인 메서드와 변수는 소문자로 시작합니다. 앤드류 셰퍼드 (Andrew Shepherd)가 코드 밑에서 지적한 것처럼, 기본적으로 'ui'변수를 자체 변수로 설정하고 있습니다. 클래스'ui' 변수를'Ui'로 정의하면 이것을 발견 할 수 있고 또한 this.ui의 추가 문자를'Ui'로 제거합니다 – Canvas