- Home /
Question by
BlimeyGamer · May 27, 2015 at 11:21 AM ·
2dcollisiontriggerload level
2D Collision detection to load level.
Hey I have a character hitting an area which loads the next level the code is below but I am unable to get it working I can't see what I am missing.
I need to add a delay of a couple of seconds to show the particles and a graphic saying level complete.
Here is the code, any help would be amazing :)
using System.Collections;
public class LevelLoader : MonoBehaviour {
private bool playerInzone;
public string LoadLevel;
// Use this for initialization
void Start () {
playerInzone = false;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.W)&& playerInzone)
{
Application.LoadLevel("Level1");
}
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Tipper")
{
playerInzone = true;
}
// ... and Play the particle system
particleSystem.Play();
}
void OnTriggerExit2D(Collider2D other)
{
if(other.tag == "Tipper")
{
playerInzone = false;
}
}
}
Comment
Answer by Ekta-Mehta-D · May 27, 2015 at 11:43 AM
hii..
I would suggest you to make one function like
IEnumurator GameOver()
{
particleSystem.Play();
Yield return new WaitForSeconds(1.5f); //change float as per your req
playerInzone = true;
}
Call this in OnTriggerEnter2D() .
I have not tested this code so check spellings.
Thanks.