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

choose a trigger RANDOMLY and clone an SPECIFIC prefab

Discussion in 'Scripting' started by josemauriciob, Oct 27, 2015.

  1. josemauriciob

    josemauriciob

    Joined:
    Mar 5, 2009
    Posts:
    662
    hi.
    i need some help on this problem please.
    i will apreciatte so much....

    I have 3 or more different kind of enemies runing
    and they randomly choose their own path.

    and I need to instantiate a prefab, OnTriggerEnter
    accord which enemy choose which trigger.

    for example....
    if green enemy choose trigger 1, ... then
    Instantiate (prefab_1, ........);

    but what if the same green enemy choose trigger 2, ... then
    Instantiate (prefab_2, ........);

    or if he choose trigger 3, then
    Instantiate (prefab_3, ........);


    my specific problem is the script structure inside the trigger, or inside on any enemy.
    choose a trigger RANDOMLY and clone an SPECIFIC prefab

    any idea please ?
    really i will apreciatte so much any kind of help with this..... :(

    how goes the script structure....
    .
    ontriggerenter picture 2.jpg
     
  2. Elmdran

    Elmdran

    Joined:
    Oct 28, 2014
    Posts:
    34
    Code (CSharp):
    1. void OnTriggerEnter(Collider coll){
    2.     if(coll.gameObject.tag == "Trigger1"){
    3.         Instantiate(prefab1....
    4.     }else if(coll.gameObject.tag == "Trigger2){
    5.        Instantiate(prefab2...
    6.    }
    7. }
     
  3. josemauriciob

    josemauriciob

    Joined:
    Mar 5, 2009
    Posts:
    662
    thanks so much ... its working ...
    but if the same soldier try to pass again... ( two times ) not work.

    thanks againa