Quantcast
Viewing all articles
Browse latest Browse all 131

Pass C# script as parameter to function

Okay I have two or more scripts in separate objects that do the same. (Complex checking inventory system checking if the clicked Button has item in it) What I need to do is make one static function containing that huge code. And now my problem is: void myFunction(script scriptName, int i) { if(script.inventorySlot[i] == texture_apple) //texture apple is assigned texture { just do something; } } So you see my problem is that multiple scripts needs to pass themselves or other scripts into myFunction() as script parameter. How to do that? This doesn`t work as well void myFunction(gameObject Object, int i) { if (Object.GetComponent() != null) target = Object.GetComponent(); if (Object.GetComponent() != null) target = Object.GetComponent(); if(target.inventorySlot[i] == texture_apple) //texture apple is assigned texture { just do something; } }

Viewing all articles
Browse latest Browse all 131

Trending Articles



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