- Home /
The question is answered, right answer was accepted
Comparing 2 objects for a Item System?
resolved this thank you guys
Answer by RudyTheDev · Dec 31, 2014 at 05:20 PM
If they only have 1 instance (since I see static
), then as @tanoshimi says:
if (res == item)
If not only 1 instance:
if (res.name == item.name)
(replace "name" with whatever your variable is that defines items uniquely)
If you want to get fancy and not write above a hundred times (assuming you class isn't derived from anything conflicting, like MonoBehaviour):
public class ResourceItem
{
public string name;
public static bool operator ==(ResourceItem a, ResourceItem b)
{
return a.name == b.name;
}
public static bool operator !=(ResourceItem a, ResourceItem b)
{
return !(a == b);
}
}
then
if (res == item)
which will work for different instances as long as the name is the same.
Follow this Question
Related Questions
Check/compare array elements 1 Answer
&& comparison not executing in Javascript 2 Answers
Separately compare coordinate values of vectors 1 Answer
How to handle different bools in 1 statement 1 Answer
Compare NavMeshSurfaces with each other 0 Answers