Hi, my obstacle keeps counting the score, while my other objects like the dropper and border walls don’t. Here’s the setup I’m using:
- The obstacle has Scorer.cs and ObjectHit.cs attached.
- The obstacle is tagged as Hit .
- The player is tagged as Player .
Here is my code:
(Scorer.cs)
> public class Scorer : MonoBehaviour
>
> {
>
> // Start is called before the first frame update
>
> int hits = 0;
>
> private void OnCollisionEnter (Collision other)
>
> {
>
> if (other.gameObject.tag != "Hit")
>
> {
>
> hits ++;
>
> Debug.Log ("You've bumped into a walls this many times: " + hits);
>
> }
> }
Object.Hit.cs
public class ObjectHit : MonoBehaviour
{
private void OnCollisionEnter (Collision other)
{
if (other.gameObject.tag == "Player")
{
GetComponent <MeshRenderer> () . material . color = Color.red;
gameObject.tag = "Hit";
}
}
}
Can you help me out? Thank you before