Making Brackey’s Doodle Jump Tutorial Infinite

Updated on May 16, 2018 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on May 15, 2018

Hello all,

 

I am following Brackeys tutorial for Doodle Jump but I am wanting to make it an infinite jumper, not just 200 platforms. I was wondering if there was anyway somebody could make a code for this to be an infinite jumper? Any ideas would be greatly appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnScript : MonoBehaviour {
public GameObject platformPrefab;
public int numberOfPlatforms = 200;
 public float levelWidth = 3f;
 public float minY = 1;
 public float maxY = 2;
// Use this for initialization
 void Start () {
 Vector3 spawnPosition = new Vector3();
for (int i = 0; i <numberOfPlatforms; i++)
 {
 spawnPosition.y += Random.Range(minY, maxY);
 spawnPosition.x = Random.Range(-levelWidth, levelWidth);
 Instantiate(platformPrefab, spawnPosition, Quaternion.identity);
 }
 }
// Update is called once per frame
 void Update ()
 {
 }
}
  • Liked by
Reply
0 on May 16, 2018

This is the link to the video of his Doodle Jump tutorial: https://www.youtube.com/watch?v=fHN-26GEVhA&t=2258s

  • Liked by
Reply
Cancel
0 on May 16, 2018
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformGen : MonoBehaviour
{
    public float m_SpawnDelay;
    [SerializeField]
    private float m_Timer;
    public Transform m_SpawnPoint;
    public float m_PlatformSpeed;
    private List<GameObject> m_Platforms;
    void Start()
    {
        m_Platforms = new List<GameObject>();
    }
    void Update()
    {
        m_Timer += Time.deltaTime;
        if (m_Timer >= m_SpawnDelay)
        {
            m_Timer = 0;
            var newPlatform = GameObject.CreatePrimitive(PrimitiveType.Cube); //Creates a new cube
            //Adds a rigidbody component so we can detect collision with it
            newPlatform.AddComponent<Rigidbody>();
            //Disables gravity so it doesn't fall
            newPlatform.GetComponent<Rigidbody>().useGravity = false;
            //Sets the spawn position of the cube
            newPlatform.transform.position = m_SpawnPoint.position;
            //Randomly sets a new scale for the platform.
            //You can modify these values to how you see fit
            newPlatform.transform.localScale = new Vector3(1, Random.Range(1,6), 1);
            //Adds it to the list
            m_Platforms.Add(newPlatform);
        }
        //Loops over all platforms and moves them across the screen
        foreach (var platform in m_Platforms)
        {
            if(platform != null)
                platform.transform.position += Vector3.right * -m_PlatformSpeed;
        }
    }
    void OnTriggerExit(Collider other)
    {
        // Destroy everything that leaves the trigger
        if (m_Platforms.Contains(other.gameObject))
        {
            m_Platforms.Remove(other.gameObject);
            Destroy(other.gameObject);
        }
    }
}

This was an answer I gave someone with a similar question the other day. Its not like his tutorial but it does spawn platforms infinitely, random sizes, and it deletes them after the exit the screen

  • Liked by
Reply
Cancel