Search Unity

conflicts among Visual Studio and MonoBehaviour Scripts

Discussion in 'Scripting' started by AdamTegkelidis, Jan 30, 2019.

  1. AdamTegkelidis

    AdamTegkelidis

    Joined:
    Jan 22, 2019
    Posts:
    10
    Hey Everyone,

    Hope you are all doing well. I am new to Unity and a few moment ago I fell into the following problem, trying to attach a C# script into an instance.

    FYI I wrote ("copied" mostly) the script inside Visual Studio, saved it and once I tried to drag&drop it onto one of my instances in the scene, I got the following message:

    unity-monobehaviour.JPG

    I took some time to look in the web for solutions where most people suggested that a built-in version of MonoBehaviour can be assigned as the default script editor inside Unity. However, once I tried to solve this by going into the preferences panel, I saw no other options in the drop-down list besides Visual Studio:

    unity-pref.JPG

    the options are:
    1. open by file extension
    2. Visual Studio 2017 (Community) and
    3. Browse (browse what and where? there is nothing related to MonoBehaniour in my desktop)

    If anyone has any clue concerning the problem and how to fix it, by all means let me know, cause I am having a really bad day here!

    Best to all of you,

    Adam.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    This post is kind of all over the place. You seem to be dealing with several issues. I'm also not sure if you're confusing "MonoBehaviour" (a base class used in Unity) with "MonoDevelop" (a code editor)?

    For your script issue, are you trying to attach a component named AssemblyInfo onto a Unity GameObject? Does this have anything to do with the .NET AssemblyInfo class? (https://msdn.microsoft.com/en-us/li...plicationservices.assemblyinfo(v=vs.110).aspx) If so, note that you can only add a component to a GameObject if it inherits from MonoBehaviour. What are you trying to accomplish with AssemblyInfo?

    Visual Studio Community has been the default C# editor for a while now. If you want to use something else (like MonoDevelop) you'll need to install it yourself.

    Anyway, what does your AssemblyInfo component look like? (Show the code, or it's hard to help much.)
     
  3. AdamTegkelidis

    AdamTegkelidis

    Joined:
    Jan 22, 2019
    Posts:
    10
    Hey @dgoyette !

    Thank you so much for the reply. Apparently it shouldn't have been something so hard to do since I am just following the instructions of a tutorial. However, I bump onto the problem I mentioned earlier.

    This is the code, I hope it does help you to understand a few things.:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DoorLeafAnimation : MonoBehaviour
    6. {
    7.     private Animator DoorAnim;
    8.    
    9.     void Start()
    10.     {
    11.        
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update() {
    16.         DoorAnim = GetComponent<Animator>();
    17.     }
    18.  
    19.     void OnTriggerEnter()
    20.     {
    21.         DoorAnim.SetBool("RunAnimation", true);
    22.     }
    23.  
    24.     void OnTriggerExit()
    25.     {
    26.         DoorAnim.SetBool("RunAnimation", false);
    27.     }
    28. }
    29.  
    I am trying to make a door leaf open and close. Once I finished the code, I tried to drag&drop it onto my door instance in the scene: this is when I get the first message.

    Let me know whether you need more info.

    PS. I will try and download MonoDevelop as well so as to give it a shot. But naturally, this shouldn't be the cause. I will let you know if it fixes everything.
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Make sure the name of the DoorLeafAnimation script file is actually "DoorLeafAnimation.cs". It seems like you've named it "AssemblyInfo.cs"?
     
    AdamTegkelidis likes this.
  5. AdamTegkelidis

    AdamTegkelidis

    Joined:
    Jan 22, 2019
    Posts:
    10
    Thank you so much!!! You just made my day dude!

    Apparently there was a conflict with the script's title; Sometimes I feel like you programmers are geniuses. :mad:

    Anyway, apologies for the newbie question and many thanks for the help!

    Cheers,

    A.