Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'Editor & General Support' started by egg_citizen, Jan 15, 2019.

  1. egg_citizen

    egg_citizen

    Joined:
    Jan 3, 2019
    Posts:
    19
    Hello, I hope you guys can help me out with atleast knowing why the following has happened and/or how to best fix it.
    I think I incorrectly closed Unity last time I was on... and now I can't add my already excisting scripts anymore, because of Error: Can't add script behaviour AssemblyInfo. The script needs to derive from MonoBehaviour!
    I get this error, when I try to add one of the existing scripts.
    It worked before, the name of the scripts hasn't changed and yes, it does start with public class Name: MonoBehaviour after determining the Using's.

    (Name in this example of course being the name of the script)
    Version 2018.3.of2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class SetValueDice : MonoBehaviour
    7. {
    8.     public int diceValue;
    9.     public Text diceText;
    10.     public Button m_RollDieButton;
    11.     public Button m_DiceButton;
    12.  
    13.     private void Start()
    14.     {
    15.         diceValue = 0;
    16.         diceText.text = "";
    17.  
    18.        m_RollDieButton.onClick.AddListener(TaskOnClick);
    19.     }
    20.  
    21.     // Update is called once per frame
    22.         void TaskOnClick()
    23.     {
    24.         if (m_DiceButton.image.color == Color.white)
    25.         {
    26.             diceValue = Mathf.RoundToInt(Random.value * 5) + 1;
    27.             diceText.text = diceValue.ToString();
    28.         }
    29.     }
    30. }
    Example code:

    Do note, this is one of the examples. None of the scripts work anymore... luckily I can still access the code, so probably not much work is lost, but still.
     
  2. egg_citizen

    egg_citizen

    Joined:
    Jan 3, 2019
    Posts:
    19
    Ok... so after I tried adding a new script... the exsisting ones reappeared on the objects... except the publics aren't recognised and as such won't be available.

    Until I fixed the problems in the scripts.
    Now everything works again.
     
    Last edited: Jan 16, 2019
  3. jpspeck129

    jpspeck129

    Joined:
    Jun 11, 2019
    Posts:
    1
    how did you fix the problem? I have the same issue and its still not working.
     
  4. Marmik_1

    Marmik_1

    Joined:
    May 18, 2019
    Posts:
    1
    I have this issue moreover public variables are not shown in inspector and on a particular script unity gives errors on correct lines. code is exactly how unity wants it to e.
     
  5. rockylixo

    rockylixo

    Joined:
    Jan 6, 2020
    Posts:
    1
    pls respond the question
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Marmik hasn't logged in for 6 months and has only ever made the single post, so good luck.
     
  7. dylanfries

    dylanfries

    Joined:
    Jul 11, 2012
    Posts:
    16