I have this script in which I’m checking to see if a gameobject variable is null. However when I run the script the console is telling me that the if statement is causing a null reference exception. Any ideas why? Both shooterPlayer and glaveRotateAround are assigned so the null reference exception isn’t coming from them.
using UnityEngine;
using System.Collections;
public class AssignShipPlayer : MonoBehaviour {
public GlaveRotateAround glaveRotateAround;
public ShooterPlayer shooterPlayer;
// Use this for initialization
void Awake () {
shooterPlayer = GetComponent<ShooterPlayer>();
}
// Update is called once per frame
void Update () {
if(shooterPlayer.curShotGO != null){
glaveRotateAround = shooterPlayer.curShotGO.GetComponent<GlaveRotateAround>();
glaveRotateAround.ship = transform.parent.transform;
}
}
}