Unity is throwing out this compiler error when I run my code
"Assets\Stealth.cs(25,13): error CS0120: An object reference is required for the non-static field, method, or property 'RaycastHit2D.collider'"
I've tried declaring the RaycastHit2D variable in multiple different ways, and all throw out a different error.
public float rotationSpeed;
public float distance;
private void Start()
{
Physics2D.queriesStartInColliders = false;
}
void Update()
{
transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
if(RaycastHit2D.collider.CompareTag("Player")){
Destroy(RaycastHit2D.collider.gameObject);
}
RaycastHit2D RaycastHit = Physics2D.Raycast(transform.position, transform.right, distance);
if (RaycastHit2D.collider != null){
Debug.DrawLine(transform.position, RaycastHit2D.point, Color.red);
} else {
Debug.DrawLine(transform.position, transform.position + transform.right * distance, Color.green);
}
}
}
It should cause a gameObject I have in the scene to destroy the player when the ray comes in contact with the player's 2D collider, and this isn't happening.