I'm making a simple platformer and I want the position to reset when you fall off the screen
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.
Answer by Ivan Kukucov · Sep 29, 2015 at 08:59 PM
Try putting a collider where the hole is and reset the position with OnTriggerEnter or OnCollisionEnter. You can look them up in the api http://docs.unity3d.com/ScriptReference/30_search.html?q=ontriggerenter
or something like this may work
if(transform.position == new Vector3(x,y,z))
{
transform.position = new Vector3(x,y,z)
}
Answer by Hurag · Jan 19, 2016 at 04:26 AM
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);
}
}
Your answer
Follow this Question
Related Questions
Instantiate prefab not in the correct position 1 Answer
How would someone go about creating multiple triggers in one script 0 Answers
How I can change my game object position.x in current position? 2 Answers
Drag Object with Touching 0 Answers
Transform.position of object not the same as shown on the inspector 1 Answer