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

Spawn continious lines

Discussion in 'Scripting' started by Metirof, Feb 5, 2018.

  1. Metirof

    Metirof

    Joined:
    Feb 5, 2018
    Posts:
    21
    Hi everyone,

    im a new unity user, im creating my first 2D game and im stuck now, im using C# and i want to make a script to spawn continious lines with random lenght (like in the game Break Liner...somthing like in the picture), and i dont know how, i searched in tutorials & manual but didnt found somthing similar.



    thanks
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,390
    What have you tried?
     
  3. Metirof

    Metirof

    Joined:
    Feb 5, 2018
    Posts:
    21
    Thanks for your quick response for now i started spawning diffrent prefabs (lines) within a periode of time using this script :
    using UnityEngine;
    using System.Collections;

    public class SpanScript : MonoBehaviour {
    public GameObject[] obj;
    public float spawnMin = 1f;
    public float spawnMax = 2f;
    // Use this for initialization
    void Start () {
    Spawny();
    }

    // Update is called once per frame
    void Spawny() {
    Instantiate(obj[Random.Range(0, obj.GetLength(0))], transform.position, Quaternion.identity);
    Invoke("Spawny", Random.Range(spawnMin, spawnMax));
    }
    }​
    its a script that i found in a tutorial but it is basically used to spawn obstacles or collectables, and its not what i wanted

    thanks
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,390
  5. Metirof

    Metirof

    Joined:
    Feb 5, 2018
    Posts:
    21
    i already done some tutorial like : space shooter ; roll a ball ; 2D UFO & Endless 2D runner.

    but still couldnt solve it on my own, what do you recommand me to learn from :) ?
     
  6. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You want to use a LineRenderer and set the positions appropriately.