Hi guys! I’m making a 2d game for my exam’s project but i have a problem. When the player touches the obstacle , he goes through him and not die , and consequently the checkpoint don’t start. Anyone can help me?
I’ve create 3 script for manage that.
Here the code CHECKPOINT:
public class Checkpoint : MonoBehaviour {
public LevelManager levelManager;
// Use this for initialization
void Start () {
levelManager = FindObjectOfType<LevelManager>();
}
// Update is called once per frame
void Update () {
}
void onTriggerEnter2D(Collider2D other)
{
if (other.name == "Player")
{
levelManager.currentCheckpoint = gameObject;
Debug.Log("Activated Checkpoint" + transform.position);
}
}
Here the code KILLPLAYER:
public class KillPlayer : MonoBehaviour {
public LevelManager levelManager;
// Use this for initialization
void Start () {
levelManager = FindObjectOfType<LevelManager>();
}
// Update is called once per frame
void Update () {
}
void onTriggerEnter2D(Collider2D other)
{
if (other.name == "Player")
{
levelManager.RespawnPlayer();
}
}
}
And here the code LEVELMANAGER:
public GameObject currentCheckpoint;
private PlayerController player;
public GameObject deathParticle;
public GameObject respawnParticle;
// Use this for initialization
void Start () {
player = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void Update () {
}
public void RespawnPlayer()
{
Instantiate(deathParticle, player.transform.position, player.transform.rotation);
Debug.Log("Player Respawn");
player.transform.position = currentCheckpoint.transform.position;
Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
}
}
Also, i post pictures with object attributes. Thanks to anyone will help me!