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

Need help. Trying to build an infiniate runner script, but getting errors. Please hel

Discussion in 'Scripting' started by Briskmedia, Feb 27, 2014.

  1. Briskmedia

    Briskmedia

    Joined:
    Feb 13, 2014
    Posts:
    9
    Here is the script I have that is giving me errors. I guessing that GetLength is not working, but I dont understand why not.


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SpawnScript : MonoBehaviour {
    5.  
    6.     public GameObject[] obj;
    7.     public float spawnMin = 1f;
    8.     public float spawnMax = 2f;
    9.  
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         Spawn ();
    14.    
    15.     }
    16.    
    17.     // Update is called once per frame
    18.     void Spawn () {
    19.  
    20.         //// Script Wont Get Length, What am I doing wrong ///
    21.         Instantiate (obj[Random.Range (0, obj.GetLength(0))], transform.position, Quaternion.identity);
    22.         Invoke("Spawn",  Random.Range (spawnMin, spawnMax));
    23.         //// Script Wont Get Length, What am I doing wrong ///
    24.        
    25.     }
    26. }
    27.  
     
  2. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    Did you assign something to obj in the inspector?
     
  3. Briskmedia

    Briskmedia

    Joined:
    Feb 13, 2014
    Posts:
    9
    Yes, Its is actually getting using GetLength right I seen, and also spawning the prefabs it seems, but they are overlapping or something. Its not assigning there current position to make sure the next ones are out past them