- Home /
Question by
snainner · Apr 17, 2021 at 03:06 PM ·
triggerbeginnerscore system
Why is my trigger collider not working?
I'm following this tutorial for a score system but it seems that the edge collider with the Is Trigger box checked isn't working. Any idea why? Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Scoring : MonoBehaviour
{
public int Score;
public Text ScoreText;
private void OnTriggertEnter2D(Collider2D other)
{
Destroy(other.gameObject);
AddScore();
Debug.Log("im triggered lol");
}
void AddScore()
{
Score++;
ScoreText.text = Score.ToString();
}
}
My trigger looks like this:
capture.png
(60.5 kB)
Comment
Answer by Harry_Drew · Apr 17, 2021 at 04:48 PM
You need to add a Rigidbody component to the object with the edge collider attached. Set the Rigidbody mode to kinematic
Answer by ahsen35813 · Apr 17, 2021 at 06:19 PM
At least one of the objects must have a non-kinematic rigidbody on it