Quantcast
Viewing latest article 19
Browse Latest Browse All 102

Answer by lodendsg

Your question isn't clear and your code doesn't help clarify it for me but here is some info that might help you

GameObject.GetComponenet() This is a costly method that can be called on game object to return an instance of a MonoBehaviour of that given type ... for example if you had a reference to a game object which you knew to contain your ClickSine script then you could call this to get the value

GameObject.Find and its variants are costly methods that can find a specific GameObject assuming it is currently 'alive' in your game ... so for example if you knew one or more GameObjects with a given name or tag did exist at that time you could find them and return a reference to them using this method.

In general I would advise against using either method. With a good design you can generally avoid using them at all and they are inefficient/costly to use. I cant advise on what changes to your structure would let you avoid their use, as noted your question and code isn't clear to me but have a think about what data you need to perform what actions and see what you can do to provide that data from known sources as opposed to doing lookups for it such as Find or GetComponent. e.g. add references to your required behaviours on your scripts i.e. public ClickSine myClickSine or when spawning put them in a collection so you can at least search fewer things and in a more controlled way.

Viewing latest article 19
Browse Latest Browse All 102

Trending Articles



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