Search Unity

Sending message to all gameobjects in the list

Discussion in 'Scripting' started by Farooqui, Apr 1, 2017.

  1. Farooqui

    Farooqui

    Joined:
    Mar 9, 2014
    Posts:
    23
    Hello everyone,
    Need a bit of help here. I am trying to place all the gameobjects that are inside OntriggerEnter collider in an array. I am not sure how to go around it. I have tried placing them into a list but I cant figure out how to sendmessage to each gameobject.

    public List<GameObject> items;
    // Use this for initialization
    void Start () {

    }
    void OnTriggerEnter(Collider other) {
    // Destroy(other.gameObject);

    if(other.gameObject.tag == "Finish" || other.gameObject.tag == "Player"){

    items.Add(other.gameObject);

    }
     
  2. Farooqui

    Farooqui

    Joined:
    Mar 9, 2014
    Posts:
    23
    Ah figured it out, its

    foreach (GameObject go in items) {
    print (go.name);
    go.SendMessage("StayStrong");
    }