Ok everything is set up on both objects and assigned in the inspector no idea why Im getting this:
NullReferenceException: Object reference not set to an instance of an object
Player:
// SeconderyWeaponLockon________________________________________________________________________________________
if (Input.GetButtonUp ("LockOn")) { // TOGGLES LOCK ON TO BE ACTIVE OR NOT ACTIVE
if (LockedOnActive == false) {
LockedOnActive = true;
} else {
LockedOnActive = false;
Crosshair1.SetActive (true);
Crosshair2.SetActive (false);
}
}
if (LockedOnActive == true) { // if lock on is active change crosshairs and activate raycast.
Vector3 fwd = transform.TransformDirection(Vector3.forward); //the direction the player is facing
Crosshair1.SetActive (false);
Crosshair2.SetActive (true);
RaycastHit hit = new RaycastHit ();
if (Physics.Raycast (transform.position, fwd, 60000))
if (Hit.collider.tag == "Red_Team") {
Hit.transform.gameObject.GetComponent<LockedOn>().IsLockedon = true;
LockedOnTarget = Hit.collider.gameObject;
}
}
//_____________________________________________________________________________________________________________
Object Hit Script:
using UnityEngine;
using System.Collections;
public class LockedOn : MonoBehaviour {
// put this on all Enemy Ships and Targets that can be targeted
public bool IsLockedon;
public GameObject LockedOnSymbol;
// Update is called once per frame
void Update () {
if (IsLockedon == true) {
LockedOnSymbol.SetActive (true);
}
}
}