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

Tips for 2d endless runner game

Discussion in '2D' started by danybr, Aug 28, 2014.

  1. danybr

    danybr

    Joined:
    Aug 28, 2014
    Posts:
    16
    Hi,this is my first post on it.
    I'm studying for develop game in unity with my team.
    we have a problem with the project of the game:
    the choices are two: static game or dynamic game.
    Whe have choose static game: the player position is fixed,background flowing endlessly but the obstacles?
    I thought of them generate from the right and scroll left until come out of the scene, and a destroyer destroys them.
    following the tutorial mike Gaig, I inserted a quad which creates obstacles and make this script :
    Code (csharp):
    1.  
    2. public class SpawnScript : MonoBehaviour {
    3.     public GameObject[] obj;
    4.     public float spawnMin = 1f;
    5.     public float spawnMax = 3f;
    6.     public Vector3 pos = new Vector3(26.10f,-0.07f,0);
    7.     public float speed = 2.0f;
    8.     void Start () {
    9.         StartCoroutine(Spawn());
    10.     }
    11.  
    12.     IEnumerator Spawn() {
    13.         while (true) {
    14.             GameObject clone;
    15.             clone = Instantiate (obj [Random.Range (0, obj.Length)], pos, Quaternion.identity) as GameObject;
    16.             //clone.transform.position += Vector3.left * Time.deltaTime * speed;
    17.             yield return new WaitForSeconds(Random.Range (spawnMin, spawnMax));
    18.  
    19.         }
    20.     }
    21. }
    22.  
    the script is, however, incomplete. I need to create obstacles and make them move to the left independently of one another, but I have no idea how to do.
    Can you help me?
    Sorry for my bad english. Thank you so much!


    EDIT: I MADE THIS:

    Code (csharp):
    1.  
    2. IEnumerator Spostamento(GameObject clone){
    3. for(int i=0;i<300;i++){
    4. clone.transform.position += Vector3.left * Time.deltaTime * speed;
    5. yield return new WaitForSeconds (0.01f);
    6. }
    7. }
    8.  
    9. IEnumerator Spawn() {
    10. while (true) {
    11. GameObject clone;
    12. clone = Instantiate (obj [Random.Range (0, obj.Length)], pos, Quaternion.identity) as GameObject;
    13. StartCoroutine(Spostamento (clone));
    14. yield return new WaitForSeconds(Random.Range (spawnMin, spawnMax));
    15. }
    16.  
     
    Last edited: Aug 28, 2014
  2. danybr

    danybr

    Joined:
    Aug 28, 2014
    Posts:
    16
    This works... but the destroyer work with collider. I associate the collider(poligonal collider) at the prefab,but when start the simulator and my player collide with it,Unity go in loop and i can't stop it (i have to kill the preocess on the task manager).
    I need to use the "void FixedUpdate()" function ?? HELP ME PLEASE :'(
     
  3. danybr

    danybr

    Joined:
    Aug 28, 2014
    Posts:
    16
    Nobody can help me?
     
  4. perracolabs

    perracolabs

    Joined:
    Apr 3, 2014
    Posts:
    29
  5. marudhu

    marudhu

    Joined:
    Sep 13, 2014
    Posts:
    2
    Hey If you are looking for 2D Endless Running with Jumping, I had found a reference game: "Mojo Run" from the Unity asset store.

    Hope it helps you.. Thanks..