- Home /
Changing Custom Object Variable
So I am building a global "Build Que" in my game. I am attempting to add custom objects to a List and then from there grab an object from the list and change a variable inside the objects class.
So far I have created a custom class and a list for the objects -
public class QueObjects
{
public int BuildID;
public int TeamID;
public int buildTimerLeft;
public bool isPaused;
}
public List<QueObjects> BuildingQue = new List<QueObjects>();
I can check if a value exists no problem, but when I try to change a variable inside the object I get an error
if (BuildingQue.Contains(QO))
{
BuildingQue[QO].TeamID++;
}
The QO comes from a parameter from, that is created as such -
QueObjects BO = new QueObjects();
Everything I try I get an error saying cannot convert from QueObject to int or bool etc.
Am I doing this wrong?
Answer by DiegoSLTS · Dec 25, 2019 at 09:13 PM
What's "QO"? If that's an instance of QueObject then just do QO.TeamID++.
List.Contains takes an object and tells you if the object is in the list (returns true or false). List's "[]" operator takes an index (an int) and returns a reference to the object at that position.
You can't pass an object to the "[]" since it's not an int, but if you already have the object (QO) you don't need to get it from the list.
Your answer
Follow this Question
Related Questions
JS Dictionary? 1 Answer
A node in a childnode? 1 Answer
How to follow a target (prefab) with the visual scripting: Behavior machine Pro? 0 Answers
Problem moving Rigidbody with UI buttons 2 Answers