- Home /
Bringing in classes from a DLL
I have made a .DLL library for a few function I use frequently to make things easier for myself, I followed instructions on 5+ tutorials on how to import it but none of them work. I have my code written properly and imported properly, it just doesn't want to work. Could anyone tell me how it REALLY works so I can use the classes and functions from my dll please? I have posted pictures as references.
Answer by orb · Sep 15, 2014 at 11:36 AM
Use namespaces to be on the safe side and avoid naming conflicts.
This simple assembly works for me:
using System;
namespace Helpers
{
public class Strings
{
public Strings()
{
}
public static string CapIt(string src)
{
if(string.IsNullOrEmpty(src)) return string.Empty;
string s = src.ToLower();
return char.ToUpper(s[0]) + s.Substring(1);
}
}
}
Use it like this:
using UnityEngine;
using Helpers;
public class TestHelpers : MonoBehaviour
{
void Start()
{
Debug.Log(Strings.CapIt("this is WRONG."));
}
}
Note that my example class probably has a terrible name.
Thank you, so I can't simply bring in my DLL I made in visual studio so I will have to write the scripts in mono develop?
I'm pretty sure you can use VS, but I don't develop on Windows, so I wouldn't know what to do. You may be referencing a .Net level which Unity doesn't support if you set it up wrong, but I dunno if that is only a problem when you call some unsupported method. There are guides on setting up an assembly in VS.
Setting up a new solution in $$anonymous$$onoDevelop as Library has worked for me, and the above code is tested and working. Just remember to have a namespace so that you have something to import via "using" statements. I think it's basically a requirement too.
Unity won't work with DLLs that's are above 3.5. $$anonymous$$ake sure that when you compile your DLL that it's in .NET 3.5
It is in 3.5, I guess I will just have to deal with the poopiness of $$anonymous$$onoDevelop.
Your answer
Follow this Question
Related Questions
I can't use some codes in dll file? 1 Answer
Including a DLL in unity? 1 Answer
Distribute terrain in zones 3 Answers
Having issues using my .dlls 1 Answer
Multiple Cars not working 1 Answer