Hello, I’m very new to c# coding and have recently been trying to make a collision detector (so the game can end). I have made a script on unity that should detect when an object has collided with another object. when i finished writing the script, a error showed up saying that the modifier “private” is not valid for this item (which i have no idea what it means. Please help!
this is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameOverDetector : MonoBehaviour
{
// Update is called once per frame
void Update()
{
Your onControllerColliderHit method is declared within the Update method. Having inline methods is not impossible since some C# versions ago, however it’s most likely not what you want. For this kind of method declarations, you cant make them private or public (because access modifiers simply make no sense in that context), which is what the compiler is complaining about.
You probably just meant to use the predefined method OnControllerColliderHit. Note the capital O. Spelling and capitalization is increadibly important in programming. someIdentifier and SomeIdentifier are most definitely not the same thing. Also, you will want to place the OnControllerColliderHit method outside the Update function, but still inside the GameOverDetector class.