when i try and add a script to an object it says 'Can't add script behaviour VisualContainerAsset. The script needs to derive from MonoBehavour !'

the code im trying to add to a plane (the object) is:

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

public class Colourobjectkey : MonoBehaviour
{

public Material matofobject;
public Color newcol;
public KeyCode changecolo;

public Colourobjectkey()
{
}

// Use this for initialization
void Start()
{
    matofobject.color = Color.black;
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(changecolo))
    {
        if (matofobject.color == Color.black)

        {
            matofobject.color = newcol;
        }
        else;
        {
            matofobject.color = Color.black;
        }
    }
       
}

}
}

and it wont work please help someone. (btw it says: ‘Can’t add script behaviour VisualContainerAsset. The script needs to derive from MonoBehavour !’ whenever i try to do it lol im probably being an idiot rn)

Hello there,

I think you must have refactored/renamed the class at some point.
The name of the class (rn: Colourobjectkey) needs to be the exact same as the name of the script, which seems to be VisualContainerAsset right now. Rename the script file and you’ll be fine!


I hope that helps!

Cheers,

~LegendBacon