So I finally got collision to work and have my player die and respawn when he touches a certain object, but this doesn’t reset the score count. Here is my script I’m using that respawns the player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class KillPlayer : MonoBehaviour
{
public int Respawn;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
SceneManager.LoadScene(Respawn);
}
}
}
And here is my script that keeps the score count:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreScript : MonoBehaviour
{
public static int scoreValue = 0;
Text score;
// Start is called before the first frame update
void Start()
{
score = GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
score.text = "Score:" + scoreValue;
}
}
So what function should I add and to which script that will reset the score to 0 upon player death? It seems I should be able to add it to the respawn function, but that doesn’t work. I hope this is clear. Much appreciated!