Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
skatefantasy

Help with Level Change Script

Question

I need help with changing the level of a simple game, when all the blocks are gone, it should go to the next level. This works fine going from level one to level two, but i need to make it so it goes to level 3,4,5 and so one tell me what i need to do to edit my script?

Ball Script:

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class Ball : MonoBehaviour {

public float multiplier = 1.05f;

public float minSpeed = 5;

public float maxSpeed = 15;

public float curSpeed = 0;

private Transform _t;

public List blocks;

void Awake() {

_t = transform;

blocks = new List();

}

// Use this for initialization

void Start () {

blocks.AddRange( GameObject.FindGameObjectsWithTag( "Block" ) );

ResetBall();

}

// Update is called once per frame

void Update () {

if( blocks.Count < 1)

WonLevel();

if(_t.position.y < -6 )

MissedBall();

}

void FixedUpdate() {

curSpeed = Vector3.Magnitude( rigidbody.velocity );

if (curSpeed > maxSpeed )

rigidbody.velocity /= curSpeed / maxSpeed;

if (curSpeed < minSpeed && curSpeed > 0 )

rigidbody.velocity /= curSpeed / minSpeed;

}

void OnCollisionEnter( Collision col ) {

rigidbody.velocity += rigidbody.velocity * multiplier;

if(col.gameObject.CompareTag( "Block" ) )

blocks.Remove( col.gameObject );

}

private void MissedBall() {

if( Lives.curlives-- < 2 )

GameOver();

else

ResetBall();

}

private void ResetBall() {

_t.position = new Vector3( Random.Range( -Player.xBoundry + 3, Player.xBoundry - 3), 0, Player.zPosition );

_t.LookAt( GameObject.FindGameObjectWithTag( "Player" ).transform.position );

rigidbody.AddRelativeForce( new Vector3( 0, 0, minSpeed ) );

}

private void GameOver() {

_t.renderer.enabled = false;

rigidbody.velocity = Vector3.zero;

_t.position = Vector3.zero;

}

private void WonLevel() {

Debug.Log( "Won Level" );

Application.LoadLevel("Level 2");

}

}

Block Script:

using UnityEngine;

using System.Collections;

public class Block : MonoBehaviour {

public BlockType blockType = BlockType.Red;

// Use this for initialization

void Start () {

MeshRenderer mr = GetComponent();

switch( blockType ) {

case BlockType.Green:

mr.material = Resources.Load( "Materials/BlockGreen mat" ) as Material;

break;

case BlockType.Blue:

mr.material = Resources.Load( "Materials/BlockBlue mat" ) as Material;

break;

case BlockType.Orange:

mr.material = Resources.Load( "Materials/BlockOrange mat" ) as Material;

break;

default:

mr.material = Resources.Load( "Materials/BlockRed mat" ) as Material;

break;

}

}

void OnCollisionEnter( Collision col ) {

Score.score += (int)blockType;

Destroy( gameObject );

}

}

public enum BlockType {

Red = 10,

Green = 25,

Blue = 50,

Orange = 100

}

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...