Search Unity

Can't add script behaviour TMP_CoroutineTween. The script needs to derive from MonoBehaviour!

Discussion in 'Scripting' started by thegrailvr, Sep 3, 2018.

  1. thegrailvr

    thegrailvr

    Joined:
    Jul 19, 2018
    Posts:
    11
    I'm trying to attach a script to a game object.

    New-> C# script
    and then drag drop onto game object.

    and this error appears.
    Can't add script behaviour TMP_CoroutineTween. The script needs to derive from MonoBehaviour!

    the script is a new one with nothing in it as follows.
    The name of the script is New


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class New : MonoBehaviour {
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
    }



    What's going on?

    furthermore,
    all preivously attached scripts on my gameobject. When I remove them and try to re-attach them, they give me the same error.
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    The name of the class has to be the same as the name of the behavior.
     
  3. unity_KvAOEiDU_455Pg

    unity_KvAOEiDU_455Pg

    Joined:
    Nov 28, 2018
    Posts:
    1
    What do you mean?
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    If the class is named "New" it must be in a file named "New.cs" in order to be attached to an object.

    Also, if the script hasn't compiled (say, if there are any compiler errors elsewhere) that will also cause this error.
     
    ELS-573 and Releasethegamer like this.
  5. jdubs_

    jdubs_

    Joined:
    Apr 13, 2021
    Posts:
    2
    i have the same problem nothing is working this is my code
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class BaseHealth : MonoBehaviour {
    7.  
    8.     public float health = 2;
    9.  
    10.     // Update is called once per frame
    11.     void Update()  {
    12.         if (health <= 0)
    13.             Destroy (gameObject);
    14.     }
    15. }
    16.  
    thank if you could help
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Make your own post, don't revive 2 year old post.
    If you have the same problem, then the solution is the same. Did you look at what people said to see if that is your problem?
     
  7. jdubs_

    jdubs_

    Joined:
    Apr 13, 2021
    Posts:
    2
    ok i will thank you tried it did not work
     
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Make your own quality post with your error in it.