Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SpawnerScript : MonoBehaviour {
  5.    
  6.     public Transform prefab;
  7.    
  8.     // Use this for initialization
  9.     void Start () {
  10.    
  11.     }
  12.    
  13.     // Update is called once per frame
  14.     //depending on the level of game(?) the chance to spawn an object will increase
  15.     //for now, if random number is 10 or smaller
  16.     void Update () {
  17.         if(Random.Range(0, 100) <= 10){
  18.             Instantiate(prefab, GetSpawnPoint(), Quaternion.identity);
  19.         }
  20.    
  21.     }
  22.    
  23.     //calculate random spawn point from the circle and return it
  24.     Vector3 GetSpawnPoint(){
  25.         Vector3 spawnPoint;
  26.         int radius = 5;
  27.        
  28.         float angle = Random.Range(0, 8) * Mathf.PI * 2;
  29.         spawnPoint = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
  30.        
  31.         return spawnPoint;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement