Missing script references

Something happened and my screen froze up after this session and now when I opened it back up, my ball doesn’t launch anymore and it won’t stick to the paddle any more.
Here is my code:


    // config params
    [SerializeField] Paddle paddle1;
    [SerializeField] float xPush = 2f;
    [SerializeField] float yPush = 15f;

    // state
    Vector2 paddleToBallVector;
    bool hasStarted = false;

	// Use this for initialization
	void Start ()
    {
        paddleToBallVector = transform.position - paddle1.transform.position;
	}
	
	// Update is called once per frame
	void Update ()
    {
        if (!hasStarted)
        {
            LockBallToPaddle();
            LaunchOnMouseClick();
        }
	}

    private void LaunchOnMouseClick()
    {
        if(Input.GetMouseButtonDown(0))
        {
            hasStarted = true;
            GetComponent<Rigidbody2D>().velocity = new Vector2(xPush, yPush);
        }

    }

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

Also getting these error codes:

Hi Penny,

What has happened is that some of your GameObjects have lost their reference to the script(s) you attached to them. If you have a look through your Hierarchy, one object at a time, and view the Inspector for each you’ll see that there will be some that have a “Script Component” but without perhaps the name of the script, e.g. “Ball.cs” and in the script field it will state it is missing.

All you need to do is drag the appropriate scripts back to the GameObjects and this will resolve the issue for you.

Hope this helps :slight_smile:

Thanks so much!

You’re a lifesaver. I could not figure it out for nothing. But it turns out, it was the ball script was gone. Once I added that back in, it started working again.

1 Like

You are very welcome Penny, glad you can move forward again :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms