Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Prefab Instance Tags

Discussion in '2D' started by RedKinetic, Mar 16, 2015.

  1. RedKinetic

    RedKinetic

    Joined:
    Nov 9, 2014
    Posts:
    20
    I am generating two different prefabs randomly and they float across the screen.
    They each have different tags set to them at Awake.

    With screen touches, I need to change the tag of just the object on screen(clone).

    What is happening is: on touch, the entire prefab is changing it's tag.

    I need to access ONE object as it comes on screen and it's tag. It has to be changed by a certain point on the screen or the player dies. Each prefab is a Rigidbody2D with collider2D.

    Accessing that one instance with the certain tag is giving me a lot of trouble.
    I use C#, let me know if you need more information. Thank you!
    Jordan
     
  2. SeasiaInfotechind

    SeasiaInfotechind

    Joined:
    Nov 17, 2014
    Posts:
    32
    Hello,
    Create a new tag "Test" in the Tag Manager and assign to gameObject which you want to be instantiate in the scene by scripting,below is given code may be help.

    public GameObject prefabs;
    voidStart()
    {
    varExample = Instantiate(prefabs, newVector3(0, 0, 0), Quaternion.identity) asGameObject;
    Example.gameObject.tag = "Test";
    }