When you look at the code in your IDE, you will see red outlines underneath the exact points in your code that have issues. When you hover your cursor over these points the IDE will tell you what the issue is.

You can even use the Show potential fixes functionality and the IDE can often fix the issue for you automatically.

Here is the code modified so that it compiles.
public class checkpoint : MonoBehaviour
{
Collider cp;
// Start is called before the first frame update
void Start()
{
cp = GetComponent<Collider>();
cp.isTrigger = true;
GameObject gameObject = GameObject.Find("Check Point");
}
private void OnTriggerEnter(Collider other)
{
cp.isTrigger = false;
}
}
You were missing declarations for your cp
and object
variables. Additionally object
is a reserved keyword in C#, so you can't use it as a variable name.
On the OnTriggerEnter function declaration the cp
parameter was missing its type Collider
.
In the body of the method the GetComponent call has incorrect syntax.
UPDATE: You can use the Destroy method to destroy the Collider component when something enters inside its bounds for the first time.
[RequireComponent(typeof(Collider))]
public class Checkpoint : MonoBehaviour
{
void Reset()
{
var collider = GetComponent<Collider>();
collider.isTrigger = true;
}
private void OnTriggerEnter(Collider other)
{
var collider = GetComponent<Collider>();
Destroy(collider);
}
}
If you want to destroy the whole GameObject that contains the checkpoint component and the Collider component you can use Destroy(gameObject);
.