Search Unity

Object Spawner

Discussion in 'Scripting' started by TheAPGames, Jan 16, 2022.

  1. TheAPGames

    TheAPGames

    Joined:
    Jun 1, 2020
    Posts:
    44
    Hello,

    I'm trying to figure out the following and i would appreciate any input from the fellow developers.

    Id like to have the player capture the flag( or an object like check point, OnEnterTrigger basically) , then spawn an object on the opposite of the checked point.

    The spawned object should last 10 seconds, if it detects player, it stays on and potentially the player takes control of it.

    If the spawned object does not detect player, it leaves ( Hopefully with an Ai, Navmesh).

    Then the player is able to catch/ trigger another flag to get another spawn object...

    Basically it is a character stuck on an island, and in order to leave the island, it has to get to the boat, however the boat is only available for a limit amount of time. However the player can try to capture another flag to get access to another boat.

    I hope i don't sound insane and was clear enough, Please see the attached image. FlowChart_Idea.png 2.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,695
    Looks good! Start coding, one feature at a time, let us know when you get hung up.
     
  3. Daxior

    Daxior

    Joined:
    Feb 10, 2020
    Posts:
    8
    Hopefully you'll find this helpfull

    Object boat = GameObject.Find("Boat"); // to find boat object and check its avability (if its not present this will be null)

    on the boat you will need script wich handles navmesh movement and script within you'll set

    IEnumerator CallBoatToRescuePoint(){ //this will make boat move between 2 points after calling this
    // here you will need to call SetDestination for your boat to come nearby
    yield return new WaitForSeconds(10);
    // and here use same SetDestination function to go away out of screen so it can wait there for another call
    }

    Since I dont know your script architecture I can only tell you that you need:
    -search for boat after colliding with checkpoint if its spawned (not null)
    -if its null just end your script there
    -if its avaliable, then start coroutine wich will set its destination on the water nearby rescuepoint inside coroutine and also will later set it away so boaut will sail off out of screen