Do you have some app logic or game logic that you want to keep in a separate project? Perhaps you want to re-use your utility functions in your next project and keep them separated from your main project. After reading this tutorial, you are able to use Visual Studio to create a .NET class library and use it from Unity3D.

Create a .NET class library with Unity3D and Visual Studio.

Lib in unity

add project

new project

rename

namespace LibTest.Core
{
public class Game
{
private int _livesLeft = 3;
public bool IsGameOver => _livesLeft == 0;
}
}

props

Here you see the assembly name and the target framework:

target framework

build

Lib in unity

using LibTest.Core;
using UnityEngine;

public class App : MonoBehaviour
{
private Game _game = new Game();

private void Update()
{
if (_game.IsGameOver)
{

}
else
{

}
}
}

And that’s it. You can now add stuff to your Game class and access it from the main project.

Written by Loek van den Ouweland on 2017-11-24.
Questions regarding this artice? You can send them to the address below.