- Home /
Checking if an object is of an instance
I have a class called MeleeWeapon that inherits from the class Item and the interface Usable. I have an array of type Item which contains some objects which are type MeleeWeapon and I would like to know how to check if they are usable or not. I have tried the following methods but both result in false being logged. Any advice?
Debug.Log ( itemType.IsAssignableFrom(typeof(Usable)));
Debug.Log (inv.items[inv.selectedHotbarSlot].item is Usable);
Comment
Best Answer
Answer by Nick4 · Aug 16, 2014 at 08:02 AM
This should work if I'm not mistaken.
Debug.Log(typeof(Usable).IsAssignableFrom(typeof(inv.items[inv.selectedHotbarSlot].item)));
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Flip over an object (smooth transition) 3 Answers
C# Class Does Not Implement Interface Member 2 Answers
Find all scripts attached to an object that implement a certain interface 1 Answer