I want to get my player to move to the beginning of level when it touches a trigger collider (called LevelEnd). I’m not quite sure if I should put the script in the LevelEnd object or my player object or how to do it. I’m using C++. Any help would be appreciated!
I probably would solve it like this:
The LevelEnd Object has a Command Container Object, which has a command defined (in this case “move to the beginning of level”).
When the player touches the LevelEnd Object, the LevelEnd Object passes that command to the player and the player executes it.
(However, I use the plugin FullInspector excessively, so maybe this approach is not really usable without full inspector)
You can have the event on the player or on the end object. Just set a trigger so that when the player hits the object the trigger is detected & sends the player off.
Personally I put the script on the object & make the new spawn point, if it’s on the same unity scene, a public game object so I can drag it onto the object in the inspector. I make the collider on the end object the trigger then ontriggerenter I transform.position the player to (spawnpoint.position). If it’s to a new unity scene then ontriggerenter triggers application.loadsceen(x)
By putting the script on the end object my player isn’t carrying around a whole bunch of stuff if it can’t be reused. Of course, if you are storing the level on playerprefs or something then you could get it back & then use it as the scene (application.loadscene(current level+1))
How do I get a reference to the player? I have this:
void onTriggerEnter() {
Transform.position =
}
Don’t have a PC here but it’s something like
void OnTriggerEnter (Collider other){
other.gameObject.transform.position =
}
This is assuming the player is the only thing that can collide with the end object.