Alright so I made this script:
using UnityEngine;
using System.Collections;
public class CannonShots : MonoBehaviour {
public Transform ballPos;
public Rigidbody Ball;
public float timeMin = 1;
public float timeMax = 3;
public float forceAmount = 1500;
void SpawnBall()
{
Rigidbody ballRigid;
ballRigid = Instantiate(Ball, ballPos.position, ballPos.rotation) as Rigidbody;
ballRigid.AddForce(ballPos.forward * forceAmount);
}
void Start() {
float timeToSpawn = Random.Range(timeMin, timeMax);
InvokeRepeating("SpawnBall", timeToSpawn, timeToSpawn);
}
}
An error pops out saying NullReferenceException: Object reference not set to an instance of an object
CannonShots.SpawnBall () (at Assets/MyAssets/Scripts/CannonShots.cs:16) . I know what this error means but I can’t seem to figure out how to fix it. So can somebody please help me and explain what the error was and correct it? Thanks!