on collision = string

hi, I am trying to make a code that will register the tag of the object it most recently collided with, but I am getting the “no monosbehaviour scripts in the file” error. I checked the file name, and they match, as I am fairly new to c# this is probably a dumb error on my part, but if you could help me that would be great.

thanks

here is the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class wandSocket : MonoBehaviour
{
    public string wandConfirmation;
    void OnCollisionEnter(Collision collision)
    {
        wandConfirmation = collision.gameObject.tag;
    }
}
  • Make sure you have no compile errors at all (even from other files). If there are any errors, even from unrelated files, nothing will work.
  • Make sure the filename and class name match perfectly. Since your class name is “wandSocket” your filename should be “wandSocket.cs”. This is case sensitive. Also note that C# convention is for class names to use PascalCase, so I’d recommend “class WandSocket” and “WandSocket.cs”
2 Likes

Thanks, it turns out that the issue was how i used a get component on a different script. this solved it, thanks.