I’m experiencing an issue with my Unity game where a collision count is being incremented at the start of the game, even though no collisions have occurred. Here is the relevant script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Scorer : MonoBehaviour
{
int hits = 0;
private void OnCollisionEnter(Collision other)
{
hits += 1;
Debug.Log("You've bumped into a thing this many times: " + hits);
}
}
When the game starts, I get the message “You’ve bumped into a thing this many times: 1” even though the player hasn’t collided with anything. How can I prevent this initial collision count and ensure the counter only increments when actual collisions happen during gameplay?