Is there an error in this lesson or am I doing something wrong?

i had to modify my SpawnNewBall method like this, code in the video throws this error

MissingComponentException: There is no ‘SpringJoint2D’ attached to the “Ball(Clone)” game object, but a script is trying to access it.
You probably need to add a SpringJoint2D to the game object “Ball(Clone)”. Or your script needs to check if the component is attached before using it.
BallHandler.SpawnNewBall () (at Assets/Scripts/BallHandler.cs:61)
BallHandler.Start () (at Assets/Scripts/BallHandler.cs:24)

    private void SpawnNewBall() {
        GameObject ballInstance = Object.Instantiate(ballPrefab, pivot.position, Quaternion.identity);       
        currentBallRigidbody = ballInstance.GetComponent<Rigidbody2D>();
        currentBallSpringJoint = pivot.GetComponent<SpringJoint2D>();
        currentBallSpringJoint.enabled = true;
        currentBallSpringJoint.connectedBody = currentBallRigidbody;
        
    }

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

Privacy & Terms