Search Unity

Help with Infinite Sidescroller

Discussion in 'Scripting' started by Zalosath, Jan 29, 2015.

  1. Zalosath

    Zalosath

    Joined:
    Sep 13, 2014
    Posts:
    687
    Hello! I need a little bit of help with my sidescroller, essentially, it spawns in Objects when I don't want it too. E.G:
    http://prntscr.com/5ymlwa
    Other than there is way too much light...

    How can I prevent this?

    Code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GroundManager : MonoBehaviour {
    5.  
    6.     public GameObject[] objects;
    7.     public float spawnMin = 1f;
    8.     public float spawnMax = 2f;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.         Begin ();
    13.     }
    14.    
    15.     void Begin ()
    16.     {
    17.         Instantiate (objects [Random.Range (0, objects.Length)],
    18.                      transform.position, Quaternion.identity);
    19.         Invoke ("Begin", Random.Range (spawnMin, spawnMax));
    20.     }
    21. }
    Thank you!
     
  2. Fydar

    Fydar

    Joined:
    Feb 23, 2014
    Posts:
    69
    I don't know about Invoke, I've never used it, but do you want to be finally Invoking Invoke?
     
  3. Zalosath

    Zalosath

    Joined:
    Sep 13, 2014
    Posts:
    687
    I do not understand what you are saying. I am new to Unity ;p. Anyway, essentially I want too make sure that the different stages of the side scroller don't go inside of each other. Instead, only create a new stage when the path is clear and it can spawn with no trouble.
     
  4. Kamalen

    Kamalen

    Joined:
    Dec 27, 2012
    Posts:
    29
    You are invoking "Begin" in Begin ; so Begin is run every frame andyou instantiate a new random object every frame.
     
  5. Zalosath

    Zalosath

    Joined:
    Sep 13, 2014
    Posts:
    687
    Yes.
     
  6. Fydar

    Fydar

    Joined:
    Feb 23, 2014
    Posts:
    69
    Yeah, thats kinda what I meant to say, you put it in a much better way
     
  7. Zalosath

    Zalosath

    Joined:
    Sep 13, 2014
    Posts:
    687
    Yes, that's what I do.