I am trying to make a combination of scripts that causes the character to touch a laser beam, then the player loses 15% health. I was using the OnTriggerEnter2D function but it wasn't working. I will list the scripts below.
BeamScript.cs
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class BeamScript : MonoBehaviour
{
public LogicScript LogicManager;
// Start is called before the first frame update
void Start(){
LogicManager = GameObject.FindGameObjectWithTag("LogicManager").GetComponent<LogicScript>();
}
private void OnTriggerEnter2D(Collider2D collider)
{
Debug.Log("Collision Found");
if (collider.gameObject.layer == 6)
{
LogicManager.DecreaseHealth(15);
}
}
}```
`LogicScript.cs`
```cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.UI;
public class LogicScript : MonoBehaviour{
public Double Score;
public Text ScoreText;
public Double ScoreSpeedMultiplier;
public Double Health;
public Text HealthText;
// Start is called before the first frame update
void Start(){
}
// Update is called once per frame
void Update(){
IncreaseScore(1);
}
public void IncreaseScore(int IncrementAmount){
Score += IncrementAmount * Time.deltaTime * ScoreSpeedMultiplier;
ScoreText.text = Math.Floor(Score).ToString();
}
public void DecreaseHealth(int DecrementAmount)
{
Health -= DecrementAmount;
HealthText.text = Health.ToString();
}
}
If I need to add any imports to either of the files or any other changes, please let me know. I know that the OnTriggerEnter2D is the problem because even the Debug.Log wouldn't show up.