Quantcast
Channel: Answers by "lodendsg"
Viewing all articles
Browse latest Browse all 102

Answer by lodendsg

$
0
0
You can create instances of a MonoBehaviour using instantiate or via AddComponenet on the GameObject

Instantiating Prefabs:
https://docs.unity3d.com/Manual/InstantiatingPrefabs.html

AddComponenet:
https://docs.unity3d.com/ScriptReference/GameObject.AddComponent.html


Aside from that you could create a non MonoBehaviour class that has a method suitable to be called as a coroutine but you will need to call it from a MonoBehaviour e.g. in your update call

StartCoroutine(myClass.Foo());


This assumes myClass is an instance of your class and Foo is your suitable method.


Beyond that you can use BackgroundWorkers and manage your own threads if you want truly multi threaded code however be aware that many aspects of the Unity engine are not thread safe ... if you want to get into multi-threading maybe checkout the Job system first as its meant to make such simpler ... not sure I agree its simpler but it is safer :)

Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>