monobehaviour !

hi
when i add a script to an object it says :

Can’t add script behaviour assemblyinfo.cs. The script needs to derive from MonoBehaviour!

what i should do ?
tnx

Derive from MonoBehavior?

Seriously. Usually errors and warnings tell what is wrong. And you can always google them to get more insight. What is wrong with reading?
A script is a class which derives from MonoBehavior and can be added to a GameObject. “Normal” classes cannot.

Maybe you should follow some tutorials to get a feeling of how to work with Unity.

Well, does your script actually derives from MonoBehaviour? Are the name of your script and the name of the class identical?

The class in your assemblyinfo.cs script should be called “public class assemblyinfo : MonoBehaviour”.

1 Like

Thank you for your replies both. Actually I do derive from MonoBehavior. That’s the script in the file named ApplyForceOnTriggerEnter.cs

using UnityEngine;
using System.Collections;

public class ApplyForceOnTriggerEnter : MonoBehaviour {

    [SerializeField]
    private Vector3 _force;

    public void OnDrawGizmos()
    {
        Debug.DrawLine(this.transform.position, this.transform.position + _force / Physics.gravity.magnitude, Color.red);
    }

    public void OnTriggerEnter(Collider col)
    {
        if (col.rigidbody != null)
        {
            col.rigidbody.AddForce(_force);
        }
    }
}

In fact, I do I am following a tutorial.

That cs file is a special project specific cs file that holds info about binary version, copyright info etc. Why unity tries to add it to a gameobject is not normal.

1 Like

Why was your question about assemblyinfo.cs then?

1 Like

Thank you a lot for your kind cooperation. I am new to unity, in fact I am a beginner in coding. I just copied the error that appeared.
Problem solved by creating a new project and new scripts files then editing code