Quantcast
Channel: appear – 100% Private Proxies – Fast, Anonymous, Quality, Unlimited USA Private Proxy!
Viewing all articles
Browse latest Browse all 19

How do I make my obstacles (separate prefabs) appear randomly in the world?

$
0
0

I am using Unity in C# to code a game similar to Google’s Dinosaur Run where random obstacles are spawned in the player’s path which they need to jump to dodge. I have 6 different prefabs (with animations) for my obstacles which use Polygon Colliders to detect collisions. How can I use an array to randomly select one of these obstacle prefabs to spawn them at various distances apart?

using System.Collections; using System.Collections.Generic; using UnityEngine;  public class ObstacleController : MonoBehaviour {     [SerializeField]     private Sprite[] sprites;           public int Type { get; set; }      private SpriteRenderer spriteRenderer;      private PolygonCollider2D polygonCollider2D;      public void Initialise()     {         spriteRenderer = GetComponent<SpriteRenderer>();         polygonCollider2D = GetComponent<PolygonCollider2D>();          int type = Random.Range(0, sprites.Length);          Type = type;         spriteRenderer.sprite = sprites[type];              } } 

Above is the code I have so far which only allows me to have sprites as obstacles whereas I want to use prefabs with set dimensions and animation properties.

The post How do I make my obstacles (separate prefabs) appear randomly in the world? appeared first on 100% Private Proxies - Fast, Anonymous, Quality, Unlimited USA Private Proxy!.


Viewing all articles
Browse latest Browse all 19

Trending Articles



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