Getting so many errors

It’s what I created.

But it’s what coming when i click on play

Sometimes it also comes like this

Please help me with this

Your transform.position.z is so far rear the camera maybe? I had some similar troubles with that. My camera positioned, for instance, at -20 in Z axis, and some element flowing on -200, and then, when playing, nothing to see there. May you can try to modify this value?

Also it seems you have some problems in Ball.cs, have you checked that?

Yes I tried that also. I have tried by setting the Z values if every object to -1 and they are clearly visible in scene and game also. But while playing, sometimes ball is invisible, sometimes paddle and sometimes blocks. And everytime I return to scene after playing, the z axis value is automatically changed.

In Ball.cs, I cannot find why this is showing the error.

Did you set the background game object to z = 10?

Nope

Please set the z-position of your background game object to 10. Did this fix the issue?


See also:

I tried after you told. But, still the same happening. What to do ?

What exactly is happening? Did you fix all error messages in your project? I’m asking because I noticed multiple threads by you displaying the same error messages in your console. It’s becoming a bit difficult for me to keep track of what you did in your project, what problems you have and and where the problems might come from.

But when I click on the error messages it takes me to visual studio and there it’s showing no errors. In all my threads now whole thing what I am asking,

  1. objects are not showing properly in game while they show properly in scene and I corrected Z axes properly. But still after playing once or twice some object’s Z axes shuffling automatically like -315 or 457 like this.
  2. While playing, when the ball hits anywhere those error messages come in console.
  3. I am asking that I want a sound to play uninterruptedly when the ball hits to loose collider and then the game over scene should shoe.
  4. Now I’m facing a new problem, my blocks are not breaking

That’s all I have asked 4 multiple questions

Due to these errors I am unable to continue the course further. Please help me with these, so that i can go ahead.


See I clicked on an error message and what it shows in visual studio. Where’s the error. In case you want to check, here’s the full code,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class GameStatus : MonoBehaviour
{

[Range(0.1f, 10f)] [SerializeField] float gameSpeed = 1f;
[SerializeField] int pointsPerBlockDestroyed = 73;
// Start is called before the first frame update
[SerializeField] int currentScore = 0;
[SerializeField] TextMeshProUGUI Score;

public int Length { get; private set; }

private void Awake()
{
    int gameStatusCount = FindObjectOfType<GameStatus>().Length;
    if (gameStatusCount>1)
    {
        Destroy(gameObject);
    }
    else
    {
        DontDestroyOnLoad(gameObject);
    }
}

private void Start()
{
    Score.text = currentScore.ToString();
}


// Update is called once per frame
void Update()
{
    Time.timeScale = gameSpeed;
}

public void AddToScore()
{
    currentScore += pointsPerBlockDestroyed;
    Score.text = currentScore.ToString();
}

}

Here’s another error


And here’s the entire code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ball : MonoBehaviour
{
[SerializeField] Paddle paddle1;
[SerializeField] float xPush = 2f;
[SerializeField] float yPush = 15f;
[SerializeField] AudioClip ballSound;
Rigidbody2D myRigidBody2D;

//State
Vector2 paddleToBallVector;
bool hasStarted = false;
//Cached component reference
AudioSource myAudioSource;
// Start is called before the first frame update
void Start()
{
    paddleToBallVector = transform.position - paddle1.transform.position;
    myAudioSource = GetComponent<AudioSource>();
    myRigidBody2D = GetComponent<Rigidbody2D>();
    myRigidBody2D.simulated = false; // -------- add this

}

// Update is called once per frame
void Update()
{
    if (!hasStarted)
    {
        LockBallToPaddle();
        LaunchOnMouseClick();
    }
   
}

private void LaunchOnMouseClick()
{

    if (Input.GetMouseButtonDown(0))
    {
        hasStarted = true;
        myRigidBody2D.velocity = new Vector2(xPush, yPush);
        myRigidBody2D.simulated = true; // -------- add this
    }
}

private void LockBallToPaddle()
{
    Vector2 paddlePos = new Vector2(paddle1.transform.position.x, paddle1.transform.position.y);
    transform.position = paddlePos + paddleToBallVector;
}

private void OnCollisionEnter2D(Collision2D collision)
{
    if (hasStarted)
    {
        AudioClip clip = ballSound[UnityEngine.Random.Range(0, ballSound.Length)];
        myAudioSource.PlayOneShot(clip);
    }
}

}

Block error


Full code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Block : MonoBehaviour
{

[SerializeField] AudioClip breakSound;

Level level;

private void Start()
{
    level = FindObjectOfType<Level>();
    level.CountBreakableBlocks();
}
private void OnCollisionEnter2D(Collision2D collision)
{
    DestroyBlock();
}

private void DestroyBlock()
{
    FindObjectOfType<GameStatus>().AddToScore();
    Destroy(gameObject);
    level.BlockDestroyed();
    AudioSource.PlayClipAtPoint(breakSound, Camera.main.transform.position);
    
}

}

Alright, first of all, try to keep only ONE thread for your issues, as Nina said.
Second of all, do not go to any further lectures until you have solved all of these errors.

You have clearly made a mistake somewhere in the editor. None of your screenshots show the inspector of the item the compiler complains about, which would be a huge help for us. Not all compilation errors have to do with code. The compiler clearly states that you are calling NULL objects, which means you have not assigned them properly, maybe in code or in the editor itself.

What I would advise you, is that you rewatch the lectures where your errors started to occur, you have missed many things there which is very hard for anyone to solve here.

Ok fine. I think that will be better

@Sibam99
are your still struggling with this?

If so, in dealing with the AudioClip error you may want to consider how Arrays are numbered in comparison to how things are counted. Hint: we don’t number the first object as 0 (zero).

As for the other two errors, without being able to see the heirarchy involved it looks like an issue I’ve struggled with in a couple of my own projects where the script with the error is being ran before the object holding a called script is spawned into the game.

This topic was automatically closed after 7 hours. New replies are no longer allowed.

Privacy & Terms