Managed C# dll not doing anything

Hello,

I have a C# dll in the plugins folder and can access all of the classes. All classes inherit from MonoBehaviour and one OnGUI method has the following test code:

GUI.Box( new Rect(10, 10, 100, 90), “Test text”);

It doesnt give me any errors, but doesn’t do anything. I am calling this method

gUIScrollBar = gameObject.AddComponent();

Am I missing something?

Thanks,
Donald

Assuming the OnGUI() method is defined in the GameController class, that it is declared correctly, and that the AddComponent() call is happening (i.e. you have that in a script that is active and in a function that is called) it should be working. Check all those assumptions; if you still can’t find the problem, post the code.

this is my test script below

public class test : MonoBehaviour
{
public GUIScrollBar gUIScrollBar;
public void Awake()
{
gUIScrollBar = (GUIScrollBar)gameObject.AddComponent(“GUIScrollBar”);
gUIScrollBar.OnGUI();
}

For some reason the gUIScrollBar is not initialized, I have attached this script to a game object. How do you instantiate the object?

Here is the entire script, I have added this script to an empty game object. It runs the script, but the GUIScrollBar is always empty. As you can see, I tried many variations, this is more conceptual to me. Is there anything obvious missing? Is it supposed to just run my components code or do I need to instantiate it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using System.Collections;
using Test.Assets.Component.GameManager.Business;

public class GUIScrollBar : MonoBehaviour
//public class test : MonoBehaviour
{
//public GUIScrollBar gUIScrollBar;
private GUIScrollBar gUIScrollBar;
public Texture2D progressBarEmpty;
public Texture2D progressBarFull;

public void Awake()
{
//Get gameobject by name
var go = GameObject.Find(“GCTest”);
//gUIScrollBar = (GUIScrollBar)go.GetComponent(“Test”); //.GetComponent(typeof(GUIScrollBar));
// print(gUIScrollBar.name);
//print(gUIScrollBar.barDisplay.ToString());
//gUIScrollBar.OnGUI();

//gUIScrollBar = (GUIScrollBar)go.GetComponent(typeof(GUIScrollBar));
// var go2 = GameObject.Find(“GUIScrollBar”);
// print(go2.tag);
/////////////gUIScrollBar = (GUIScrollBar)gameObject.GetComponent(typeof(GUIScrollBar));
//gUIScrollBar = gameObject.AddComponent();
//////////////// gUIScrollBar = (GUIScrollBar)gameObject.GetComponent(typeof(GUIScrollBar));
var x = GetComponent(“GUIScrollBar”);
print(x.name);
// gUIScrollBar = (GUIScrollBar)gameObject.AddComponent(“GUIScrollBar”);

///var test = (GUIScrollBar)gameObject.AddComponent(“GUIScrollBar”);
// gUIScrollBar.OnGUI();
//print(“hello”);

// gUIScrollBar.barDisplay = 60;
// gUIScrollBar.progressBarEmpty = progressBarEmpty;
// gUIScrollBar.progressBarFull = progressBarFull;
}

//This code is the code in the component below and it works if I run it here
public void OnGUI()
{
//////////////// gUIScrollBar.OnGUI();
// gUIScrollBar = gameObject.AddComponent(); //???

/// gUIScrollBar.barDisplay = 60;
//////// // draw the background:
//////// GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
//////// GUI.Box(new Rect(0, 0, size.x, size.y), progressBarEmpty);
//////// // draw the filled-in part:
//////// GUI.BeginGroup(new Rect(0, 0, size.x * barDisplay, size.y));
//////// GUI.Box(new Rect(0, 0, size.x, size.y), progressBarFull);
//////// GUI.EndGroup();
//////// GUI.EndGroup();
////////// GUI.Box(new Rect(10, 10, 100, 90), “Test text”);

}
}

I noticed one thing, if I drag and drop the method from the dll onto a gameobject in the ide it works fine, If I attempt to drag and drop the source class file, I get the error :

can’t add script behaviour the scripts file name does not match the new name of the class defined in this script

Here is the definition of the class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using System.Collections;

namespace Test.Assets.Component.GameManager.Business
{
public class GUIScrollBar : MonoBehaviour

First, general observations about posting code in the forums: use ‘code’ tags so formatting is preserved; and edit; most of the code you posted is commented out. Don’t ask people to wade through line after line of ‘not relevant to the question’ code – be it because it’s commented, or because it’s unrelated.

Actually namespaces are working fine within my dll