I’m doing a 2D game and I need to detect collision of an object with a prefab with Ground tag. Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OvercomeObject : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public static void OnCollisionEnter(Collision collision) {
if(Collision.collider.CompareTag("Ground")) {
Debug.Log("Collided");
}
}
}
Unity says:
an object reference is required for the non-static field method or property ‘Collision.collider’
I was looking for solution, but I didn’t found it. Help please!