Unity3D: find object with tag

Trabla: Unity3D: find object with tag

Solving:

Use class GameObject 
method FindGameObjectWithTag - for single object
method FindGameObjectsWithTag  - for set of objects

Example script:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class MyScript : MonoBehaviour {

    public GameObject gameController;

    // Use this for initialization
    void Start () {
   
        if (gameController == null) {
       
            gameController = GameObject.FindGameObjectWithTag( "GameController" );

        }

    }


    // Update is called once per frame
    void Update () {
   
    }
}

No comments:

Post a Comment