i keep getting the following error
NullReferenceException: Object reference not set to an instance of an object
heatSeakingProjectile.Update () (at Assets/Scripts/GamePlay/heatSeakingProjectile.cs:27)
void Update ()
{
if (Input.GetMouseButton (0)) {
foreach (Transform child in transform) {
if (child.tag == "heatSeak") {
Rigidbody clone;
clone = Instantiate (Resources.Load ("gamePlay/heatSeak"), child.position, child.rotation)as Rigidbody;
print(clone.velocity);// error occurring here
}
}
}
}
This line of code is where the error actually start:
clone = Instantiate (Resources.Load ("gamePlay/heatSeak"), child.position, child.rotation)as Rigidbody;
What type of asset are you trying to instantiate?
Isn’t heatSeak a Game Object?
Could it be that heatSeak is a gameObject with a RigidBody on it?
I also suggest you do this:
private GameObject heatSeakPrefab;
void Start()
{
heatSeakPrefab = Resources.Load ("gamePlay/heatSeak", typeof(GameObject)) as GameObject;
}
void Update()
{
if (Input.GetMouseButton (0))
{
foreach (Transform child in transform)
{
if (child.CompareTag("heatSeak") )
{
Rigidbody clone;
clone = Instantiate (heatSeakPrefab, child.position, child.rotation)as Rigidbody;
print(clone.velocity);// error occurring here
}
}
}
}