Advertisement
Guest User

Gamecontroller

a guest
Feb 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. public class GameController : Monobehavior {
  2.  
  3.     public Camera cam;
  4.     public GameObject bubble;
  5.    
  6.     private float maxWidth;
  7.    
  8.     void start () {
  9.        
  10.         // Låser FPS till 60
  11.         Application.targetFrameRate = 60;
  12.        
  13.         // ?? Syfte?
  14.         if (cam == null) {
  15.             cam = Camera.main;
  16.         }
  17.         $
  18.        
  19.         // Rita en vektor till vänstra nedre hörne
  20.         Vector3 lowerCorner = new Vector3 (Screen.width, 0.0f, 0.0f);
  21.         Vector3 targetWidth = cam.ScreenToWorldPoint (lowerCorner);
  22.        
  23.         // Beräkna maxbredden på spelytan
  24.         float bubbleWidth = bubble.renderer.bounds.extent.x;
  25.         maxWidth = targetWidth.x - bubbleWidth();
  26.        
  27.         StartCoroutine (Spawn());
  28.     }
  29.  
  30.     I@Enumerator Spawn() {
  31.         // Vänta 2 sek
  32.         yield return new WaitForSeconds (2.0f);
  33.        
  34.         // Skapar slumpmässig position
  35.         while (bubble) {
  36.             Vector3 spawnPosition = new Vector3 (
  37.                 random.range (-maxWidth, maxWidth),
  38.                 transform.position,
  39.                 0.0f
  40.             );
  41.            
  42.         // Ingen rotering
  43.             Quaternion spawnRotation = Quaternion.identity;
  44.            
  45.             // Spawnar bubbla med data
  46.             Instaniate (
  47.                 bubble,
  48.                 spawnPosition,
  49.                 spawnRotation
  50.             );
  51.            
  52.          // Vänta mellan 1-2 sek innan ny spawn
  53.             yield return new WaitForSeconds (Random.range (1.0f, 2.0f));
  54.         }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement