I get this error when playing the game and the class doesn’t work. These are my codes:
Ball.cs
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
public float maxVelocity = 20;
public float minVelocity = 15;
void Awake () {
rigidbody.velocity = new Vector3(0, 0, -18);
rigidbody.AddForce (1, 0, 1);
}
void Update () {
//Make sure we stay between the MAX and MIN speed.
float totalVelocity = Vector3.Magnitude(rigidbody.velocity);
if(totalVelocity>maxVelocity){
float tooHard = totalVelocity / maxVelocity;
rigidbody.velocity /= tooHard;
}
else if (totalVelocity < minVelocity)
{
float tooSlowRate = totalVelocity / minVelocity;
rigidbody.velocity /= tooSlowRate;
}
//Is the ball below -3? Then we're game over.
if(transform.position.z <= -6){
BreakOut.SP.LoseGame();
}
}
}
Block1.cs
using UnityEngine;
using System.Collections;
public class Block1 : MonoBehaviour {
void OnCollisionExit(Collision collisionInfo)
{
if (collisionInfo.gameObject.name == "BallPrefab")
{
Destroy(gameObject);
BreakOut.SP.HitBlock ();
}
}
}
These are error message:
-
NullReferenceException: Object
reference not set to an instance of
an object Block1.OnCollisionExit
(UnityEngine.Collision collisionInfo)
(at Assets/AAAAAA/Block1.cs:10) -
NullReferenceException: Object
reference not set to an instance of
an object Block1.OnCollisionExit
(UnityEngine.Collision collisionInfo)
(at Assets/AAAAAA/Block1.cs:10) -
NullReferenceException: Object
reference not set to an instance of
an object Ball.Update () (at
Assets/AAAAAA/Ball.cs:29)
I know there are similar question but I can’t understand much becuase their situation doesn’t look like mine. I am a begginer and not good at English so please answer simply and the way to fix it. Thank you very muc