I have a basic scene with nothing in it. In the Project hierarchy, I only have 2 folders: Scripts and Scenes. Inside Scripts, I have Timer.cs, UIHandler.cs, and a Tests directory. Inside the Tests directory, I have Tests.asmdef and TimerTest.cs.
Here is the tree-view of the Assets folder:
Assets
│ Scenes.meta
│ Scripts.meta
│
├───Scenes
│ SampleScene.unity
│ SampleScene.unity.meta
│
└───Scripts
│ Tests.meta
│ Timer.cs
│ Timer.cs.meta
│ UIHandler.cs
│ UIHandler.cs.meta
│
└───Tests
Tests.asmdef
Tests.asmdef.meta
TimerTest.cs
TimerTest.cs.meta
Tests.asmdef and TimerTest.cs are for the unit testing I have made for the Timer.cs file, which is a custom Timer script, which does not inherit from MonoBehaviour.
UIHandler.cs is for handling changing the UI whenever the Timer reaches the MaxTime.
Unfortunately, this is where the errors come into play. In the current state, TimerTest.cs can’t find my Timer.cs script. Visual Studio 2022 says “The type or namespace name ‘Timer’ could not be found (are you missing a using directive or an assembly reference?)”. Unity says the same thing.
So, I thought to move the Timer.cs script up into the Tests/ directory. That fixed the errors for that script, but then UIHandler.cs starts throwing the same error. Then, I tried moving Timer.cs down into the base Assets directory, which caused UIHandler.cs to work again, but TimerTest.cs threw errors again. So it seems like the script only has errors because of the unit testing folder???
I tried giving the Timer a namespace, so that hopefully that just so happens to allow it to find my script. Nope. Instead, it can’t find the namespace as well.
I am confused. What can I do to fix this error from occurring? Do I have to get rid of the unit testing? Can I somehow get the unit tests to find the script, as well as other scripts being able to use the Timer? Or is the only solution just giving up and scrapping this entire thing?