Y
Y
yraiv2022-02-04 10:21:52
Unity
yraiv, 2022-02-04 10:21:52

How to get data from list?

I need to get data from list. I have gameobjects saved there, I need to take the last one, how to do it?

private GameObject mob;
    private List<GameObject> mobs;


void OnTriggerStay2D(Collider2D collider)
    {

        if (collider.gameObject.tag == "Zombie")
        {
            if (mobs == null) return;
            this.mob = mobs.Count;// я не знаю как взять, подскажите 
            target = mob.GetComponent<Transform>();
            transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, Mathf.Atan2(target.transform.position.y - transform.position.y, target.transform.position.x - transform.position.x) * Mathf.Rad2Deg + 90);
            Fire();
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Farawa, 2022-02-04
@yraiv

mobs[mobs.count-1];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question