Fix problem in script
I want the player not to return from the beginning of the scene
I want to go back to the flag
PlayerLife
public class PlayerLife : MonoBehaviour {
public AudioClip deathSound;
AudioSource audioS;
//public GameObject checkPoint;
bool alive = true;
Animator anim;
PlayerController player;
// Use this for initialization
void Start () {
player = FindObjectOfType<PlayerController>();
audioS = gameObject.GetComponent<AudioSource>();
anim = GetComponentInParent<Animator>();
GameManager.gm.UpdateHUD();
}
// Update is called once per frame
void Update () {
}
public void LosesLife()
{
if(alive)
{
audioS.clip = deathSound;
audioS.Play();
alive = false;
anim.SetTrigger("Death");
GameManager.gm.SetLives(-1);
gameObject.GetComponent<PlayerController>().enabled = false;
//player.transform.position = checkPoint.transform.position;
}
}
public void Reset()
{
if(GameManager.gm.GetLives()>=0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
else
{
SceneManager.LoadScene(4);
}
}
}
KillPlayer
public class KillPlayer : MonoBehaviour {
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Player"))
{
other.gameObject.GetComponent<PlayerLife>().LosesLife();
}
}
}