Newbie: GameObject position change when trigger

I am new to Unity, and I figured that to get me started i might just make a simple platformer game.

So the player falls off the platform, hits the lava and then spawns at the start of the scene.

The problem is that I can’t figure out how to get the GameObject to change it’s position.

What am I doing wrong? :face_with_spiral_eyes:

void OnTriggerEnter(Collider t){
		player.transform.position = Vector3(0,6,0);
}

Sean

At first you need to make sure that you applied a rigidbody or character controller to your player and that the gameobject where you applied the script with OnTriggerEnter has a collider with the trigger checkbox enabled.

In addition you could think about just reloading the scene once you hit the lava so everything will be resetted as well (enemies/traps/coins/…).

I applied the charater controller to my player, and also the is trigger checbox is enabled.

At first I tried to reset the scene with the code:

Application.LoadLevel("Level1");

But for some reason that also reset my script, where I apply a death counter. If i use the code:

void Awake() {
DontDestroyOnLoad(this);
}

The death counter just duplicates, and there is a lot of 1’s.

So I figured that changing the position of my gameobject would be the best solution.

:face_with_spiral_eyes:

I’m sorry if I’m way off target, but experimenting with the script in Unity has been fun.
I’d love to learn more about it :slight_smile:

You need to add new before your Vector3.

player.transform.position = new Vector3(0, 6, 0);

Also, if you want to do as Arterie suggests, you can make your death counter static. Static variables don’t reset on scene change (unless you reset it in the script itself)

Found out that i had to add new before Vector3.

The problem was at the code:

player.transform.position = new Vector3(0,6,0);

//Should have been:
t.gameObject.transform.position = new Vector3(0,6,0);

Thank you for your help though! Much appreciated! :smile: