Quantcast
Channel: Questions in topic: "side scroller"
Viewing all articles
Browse latest Browse all 72

How do I generate obstacles in 2D side scroller?

$
0
0
I am building an endless 2D side scroller and I have created an object that will end the game when the player collides with it. The question I have, however, is how to have obstacles generate with a random frequency, and come at the player on one axis. Here is my code so far using UnityEngine; using System.Collections; public class obstacleScript : MonoBehaviour { // Use this for initialization void Start() { } float moveSpeed = 2.5f; public static Object Instantiate(Object original, Vector3 position, Quaternion rotation); // Update is called once per frame void Update() { //makes obstacle move towards player transform.Translate(Vector3.left * moveSpeed * Time.deltaTime); } //Detects if player hits an obstacle void OnTriggerEnter2D(Collider2D other) { //If a gameObject with the tag "Player" enters this trigger, load a scene. if (other.gameObject.CompareTag("Player")) { print("object hit"); Application.LoadLevel("Game Over Scene"); } } } Currently, the error I am getting is that I have to attach a body to my instantiate line.

Viewing all articles
Browse latest Browse all 72

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>