Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Spawn Gameobject when its not at the position?

Discussion in 'Scripting' started by NewIceDE, Jan 23, 2014.

  1. NewIceDE

    NewIceDE

    Joined:
    Nov 27, 2013
    Posts:
    10
    Hello,

    i don´t know how to check if the gameobject is already there?

    This is my script for spawning the gameobject:

    Code (csharp):
    1. // The object to be spawned
    2.    var SpawnObject : GameObject;
    3.    
    4.    // in seconds
    5.    var SpawnStartDelay : float = 0;
    6.    var SpawnRate: float = 120.0;
    7.    
    8.    function Start()
    9.    {
    10.        InvokeRepeating("Spawn", SpawnStartDelay, SpawnRate);
    11.    }
    12.    
    13.    // Spawn the SpawnObject
    14.    function Spawn()
    15.    {
    16.        Instantiate(SpawnObject, transform.position, transform.rotation);
    17.    }
    How can i improve the scrip, that it only spawns the object when the gameobject is not there, but when it´s there that i doesn´t spawn the gameobject?

    Thanks:)
     
  2. NewIceDE

    NewIceDE

    Joined:
    Nov 27, 2013
    Posts:
    10
    anyone can help me?