Search Unity

can't add script behaviour the script needs to derive from monobehaviour

Discussion in 'Scripting' started by Nixel2013, Jul 31, 2019.

  1. Nixel2013

    Nixel2013

    Joined:
    May 9, 2019
    Posts:
    143
    I can't find the error why it doesn't let me put the script on an object


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

    public class PantallaRecibeBoton : MonoBehaviour
    {
    public string TextScreen;
    public TextMesh Pantalla;

    void Update()
    {
    Boton boton = GetComponent<Boton>();
    TextScreen = boton.texto;

    Pantalla = (TextMesh)GameObject.Find("Cargando").GetComponent<TextMesh>();

    Pantalla.text = "" + TextScreen;
    }
    }
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Is your script file named the same as your class name? (note the caps)
     
    Joe-Censored likes this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    When you post code, use [code ]code tags[/code]

    You will need to fix all compiler errors in your script before you can attach it. Do you have compiler errors when you open up Unity's console?
     
    Joe-Censored likes this.