Hey! So I have a script so that the player loses health on a collider. It worked well however, it worked on every single collider and I do not want that. So I added an IF statement saying it should only do that if the tag is set to "Enemy" however, it does not work at all now unless I remove the If statement but then I have the problem as above, If anyone can help I would be grateful!
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour {
[SerializeField]
private Stat health;
// Use this for initialization
private void Awake()
{
health.Initialize();
}
// Update is called once per frame
void Update ()
{
if (health.CurrentVal == 0)
{
SceneManager.LoadScene ("02");
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (gameObject.tag == "Enemy")
{
health.CurrentVal -= 10;
}
}
}
↧