Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameController : Monobehavior {
- public Camera cam;
- public GameObject bubble;
- private float maxWidth;
- void start () {
- // Låser FPS till 60
- Application.targetFrameRate = 60;
- // ?? Syfte?
- if (cam == null) {
- cam = Camera.main;
- }
- $
- // Rita en vektor till vänstra nedre hörne
- Vector3 lowerCorner = new Vector3 (Screen.width, 0.0f, 0.0f);
- Vector3 targetWidth = cam.ScreenToWorldPoint (lowerCorner);
- // Beräkna maxbredden på spelytan
- float bubbleWidth = bubble.renderer.bounds.extent.x;
- maxWidth = targetWidth.x - bubbleWidth();
- StartCoroutine (Spawn());
- }
- I@Enumerator Spawn() {
- // Vänta 2 sek
- yield return new WaitForSeconds (2.0f);
- // Skapar slumpmässig position
- while (bubble) {
- Vector3 spawnPosition = new Vector3 (
- random.range (-maxWidth, maxWidth),
- transform.position,
- 0.0f
- );
- // Ingen rotering
- Quaternion spawnRotation = Quaternion.identity;
- // Spawnar bubbla med data
- Instaniate (
- bubble,
- spawnPosition,
- spawnRotation
- );
- // Vänta mellan 1-2 sek innan ny spawn
- yield return new WaitForSeconds (Random.range (1.0f, 2.0f));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement