why do I get the above error when I try to switch weapons ?(its either line 93 or 102)
my C# code:
using UnityEngine;
using System.Collections;
public class FPShooting : MonoBehaviour {
//generic prefabs
public GameObject ShotPrefab;
public AudioClip pistolsound;
//gun prefabs
public GameObject PX1;
public GameObject LaserBlade;
//guntypeequip
public string guntype = "pistol";
public string pistoltype = "PX1";
public string knifetype = "LaserBlade";
//has weapon
public bool hasPistol = false;
public bool hasHeavy = false;
public bool hasKnife = false;
//private gameobjects
GameObject currentKnife;
GameObject currentPistol;
//gun stats
//PX1
float PX1bulletImpulse = 60;
// Use this for initialization
void Start () {
currentKnife = GameObject.Find(knifetype);
currentPistol = GameObject.Find(pistoltype);
if(hasHeavy == true){
WeaponDisable();
}else if(hasPistol == true){
guntype = "pistol";
WeaponDisable();
currentPistol.SetActive(true);
}else if(hasKnife == true){
guntype = "knife";
WeaponDisable();
currentKnife.SetActive(true);
}else{
guntype = "N/A";
}
}
void WeaponDisable(){
LaserBlade.SetActive(false);
PX1.SetActive(false);
}
// Update is called once per frame
void Update () {
if( Input.GetButtonDown("Fire1") ) {
//Start Attack Code//
if( PX1.activeSelf == true ){
audio.PlayOneShot(pistolsound);
Camera cam = Camera.main;
GameObject Shot = (GameObject)Instantiate(ShotPrefab, cam.transform.position + cam.transform.forward, cam.transform.rotation);
Shot.rigidbody.AddForce( cam.transform.forward * PX1bulletImpulse, ForceMode.Impulse);
}
}
if( Input.GetButton("Fire1") ) {
if(LaserBlade.activeSelf == true) {
}
}
//End Attack Code//
if( Input.GetKeyDown ( "1" )){
if(hasKnife == true){
guntype = "knife";
WeaponDisable();
currentKnife = GameObject.Find(knifetype);
currentKnife.SetActive(true);
}
}
if( Input.GetKeyDown ( "2" )){
if(hasPistol == true) {
guntype = "pistol";
WeaponDisable();
currentPistol = GameObject.Find(pistoltype);
currentPistol.SetActive(true);
}
}
if( Input.GetKeyDown ( "3" )){
if(hasHeavy == true){
WeaponDisable();
guntype="Heavy";
}
}
}
}
thanks in advance
V.