Hi all. Some questions to check if my understanding is right.

Hi all. I just started learning C# on unity. I am following a tutorial and I am having a slight problem. The tutorial is Learn to Code by Making Games by Ben Tristem.

I have been trying to figure out what is the problem with my script. I went back to all the tutorial but I still couldn’t figure out.

I have uploaded the problem.

http://www.gamebucket.io/game/4a79944a-0946-41e1-8ea9-18a165461ecc

If I press start, it goes on correctly. It loads level correctly.
However, when I press start after it loads level 1, if I stay idle (I don’t click anything, balls stay stationary), it jumps straight to the game over scene after a few seconds. I can’t figure out which part of the script is causing this. It’s like there is a “hidden idle timer” if that makes sense.

Hope someone can help me. Thank you.

LevelManager script

 using UnityEngine;
using System.Collections;

publicclassLevelManager:MonoBehaviour{

publicvoidLoadScene(stringname){

Application.LoadLevel(name);
}
publicvoidQuitScene(){

Application.Quit();
}

publicvoidbrickDestroyed(){
if(Brickblock.brickCount<=0){
LoadNextLevel();
}
}

publicvoidLoadNextLevel(){

Application.LoadLevel(Application.loadedLevel+1);

}

}

Brickblock script

using UnityEngine;
using System.Collections;

publicclassBrickblock:MonoBehaviour{

publicSprite[]hitSprites;
publicstaticintbrickCount=0;

privateinttimesHits;
privateLevelManagerlevelManager;
privateboolisBreakable;

//Usethisfor initialization
voidStart(){
timesHits=0;
isBreakable=(this.tag=="Breakable");

if(isBreakable){
brickCount++;
}

levelManager=GameObject.FindObjectOfType<LevelManager>();
}

//Updateiscalledonceper frame
voidUpdate(){

}

voidOnCollisionEnter2D(Collision2DCollision){
if(isBreakable){
hitsCounter();
}
}

voidhitsCounter(){
timesHits++;
intmaxHits=hitSprites.Length+1;
if(timesHits>=maxHits){
brickCount--;
levelManager.brickDestroyed();
Destroy(gameObject);
}else{
LoadSprites();
}
}
voidLoadSprites(){
intspriteValues=timesHits-1;

if(hitSprites[spriteValues]){
this.GetComponent<SpriteRenderer>().sprite=hitSprites[spriteValues];
}
}

}

lose collider script

using UnityEngine;
using System.Collections;

publicclassLoseCollider:MonoBehaviour{

privateLevelManagerlevelManager;

voidOnTriggerEnter2D(Collider2DTrigger){
levelManager=GameObject.FindObjectOfType<LevelManager>();
levelManager.LoadScene("Game_Over");
}

voidOnCollisionEnter2D(Collision2DCollision){
print("Collision");
}
}

Ball script

using UnityEngine;
using System.Collections;

publicclassBall:MonoBehaviour{

privatePaddlepaddle;

//Declarevariablesand naming
privateVector3paddleToBallVector;
privateRigidbody2Drb2d;
privateboolGameStart=false;

privatevoidAwake(){
rb2d=GetComponent<Rigidbody2D>();
}

//Usethisfor initialization
voidStart(){
paddle=GameObject.FindObjectOfType<Paddle>();
paddleToBallVector=this.transform.position-paddle.transform.position;

}

//Updateiscalledonceper frame
voidUpdate(){

//Gamehavenot start

if(!GameStart){
this.transform.position=paddle.transform.position+paddleToBallVector;
}

//Gamestartonmouse click

if(Input.GetMouseButtonDown(0)){

this.rb2d.velocity=newVector2(3f,15f);
GameStart=true;
print("MouseClicked");

}
}
}

hi all sorry to bump the thread. Just an update. After some googling I managed to figure out the Application.Load is an old script. I have made all the changes using UnityEngine.SceneManagement but apparently it’s still having this weird problem.

The game is currently on autoplay, and will start once left mouse is clicked.
however, if I stay idle on any level after the I clicked start (the first scene/screen), the next scene/screen jump straight to my game over scene after a few seconds.

Hope someone can help me identify my problems. thank you.

using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class LevelManager : MonoBehaviour {

    public void LoadScene(string name){
        Brickblock.brickCount = 0;
        SceneManager.LoadScene (name);
    }
    public void QuitScene(){
   
        Application.Quit ();
    }

    public void brickDestroyed(){
        if (Brickblock.brickCount <= 0) {
            LoadNextLevel ();
        }
    }

    public void LoadNextLevel(){
        Brickblock.brickCount = 0;
        SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex + 1);

    }

}

===========================
I didn’t want to make a new thread so I am posting a 2nd question, hope someone can help me.

I am unable to point the startcolour of a particle system to the game object color.

The current script I am in is a game object. What I am trying to do was making the particle effect the same color as the game object.

This is what I mean.

public GameObject particlesVfx;
  // this allows me to attach the particle system game object into my current game object
  
  void particlesEffect (){
       GameObject particlesVfxObject = Instantiate (particlesVfx, transform.position, Quaternion.identity) as GameObject;
       particlesVfx.GetComponent<ParticleSystem> ().startColor = gameObject.GetComponent<SpriteRenderer> ().color;
     }

This allows me to make the particle the same color as the current game object but it is depreceated.

Please let me know what I did wrong.

Thank you very much.