I am a reeeeeeeeeeeeeeeeeealy new beginner and my friend told me to start with a platformer. I’m trying to make the character reset back to the original position once it falls down. I’m trying to use if statements but what I’m really trying to find is how to find the object’s current y position so it can alert the script and reset.
2 Answers
2Try putting a collider where the hole is and reset the position with OnTriggerEnter or OnCollisionEnter. You can look them up in the api Unity - Scripting API:
or something like this may work
if(transform.position == new Vector3(x,y,z))
{
transform.position = new Vector3(x,y,z)
}
Make a Empty game object (Shortcut CLTR+SHIFT+N)) and attach it to Main Camera , and add collider to it, and then go make a script named for example “killbox” .
Here is my C# script about it , try to understand it it’s not that hard i guess.
using UnityEngine;
using System.Collections;
public class Killbox : MonoBehaviour {
void Start() {
}
void OnTriggerEnter2D(Collider2D col) {
Application.LoadLevel (Application.loadedLevel);
}
}