Hi guys! I’m new to c # and currently have a question, please help !;
The question is the following: how can I add a variable or property? (I don’t know what it is called) to an array or list of GameObject?
I have to make a list of objects (GameObject), since I am not sure how many objects I have to add in the list, I want all the objects that are inside the list to be modified, without having to be placing object [0]. GetComponent, object [ 1] .GetComponent, object [2] .GetComponent, and so on.
I hope you give me to understand.
For example, I want to access the component of a GameObject, it has a script and within it there are two properties, I want all the components of the objects in the list to be “modified” in “General”.
This is what i could do:
public class ObjectList : MonoBehaviour
{
public bool targetHit;
public List<GameObject> hitOb = new List<GameObject>();
void update(){
if (targetHit == true)
{
gameObject.GetComponent<HitMe>().YouHitMe();
}
if (targetHit == false)
{
gameObject.GetComponent<HitMe>().YouNotHitMe();
}
}
}
I know it must be wrong.
YouNotHitMe and YouHitMe are the two properties of the script that I want to render.
I do not speak English much, I am using Google Translator, I hope it is understood.