Premièrement, j'ai besoins de téléporter mon jouer sur la position d'un gameobject sur trouvant dans un tableau
J'ai essayé
Code : Tout sélectionner
transform.position = playerGroupSpawn[0].transform.position;
Code : Tout sélectionner
NullReferenceException: Object reference not set to an instance of an object
battleController.changescene () (at Assets/script/battleController.cs:48)
battleController.OnTriggerEnter (UnityEngine.Collider other) (at Assets/script/battleController.cs:35)
Code : Tout sélectionner
public string battleSceneToLoad;
public GameObject[] playerGroupSpawn;
bool ifcombat = false;
void Start() {
}
void Update() {
playerGroupSpawn[0] = GameObject.Find("point1");
playerGroupSpawn[1] = GameObject.Find("point2");
playerGroupSpawn[2] = GameObject.Find("point3");
playerGroupSpawn[3] = GameObject.Find("point4");
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "cityBattle")
{
changescene();
}
}
void changescene()
{
SceneManager.LoadScene(battleSceneToLoad, LoadSceneMode.Additive);
Scene nextScene = SceneManager.GetSceneAt(1);
SceneManager.MoveGameObjectToScene(gameObject, nextScene);
SceneManager.UnloadSceneAsync("terrain");
transform.position = playerGroupSpawn[0].transform.position;
}
Code : Tout sélectionner
Unloading the last loaded scene Assets/terrain.unity(build index: 0), is not supported. Please use SceneManager.LoadScene()/EditorSceneManager.OpenScene() to switch to another scene.
UnityEngine.SceneManagement.SceneManager:UnloadSceneAsync(String)
battleController:changescene() (at Assets/script/battleController.cs:37)
battleController:OnTriggerEnter(Collider) (at Assets/script/battleController.cs:28)
Voici le code pour changer de scene
Code : Tout sélectionner
void changescene()
{
SceneManager.LoadScene(battleSceneToLoad, LoadSceneMode.Additive);
Scene nextScene = SceneManager.GetSceneAt(1);
SceneManager.MoveGameObjectToScene(gameObject, nextScene);
SceneManager.UnloadSceneAsync("terrain");
transform.position = playerGroupSpawn[0].transform.position;
}