error CS0118: `EnterVehicle.Vehicle' is a `field' but a `type' was expected
I have an error in my script, I need help please (just lign 9)
the script :
using UnityEngine; using System.Collections;
public class EnterVehicle : MonoBehaviour { public GameObject Vehicle; public GameObject Player; public GameObject PlayerBackup; private bool inVehicle = false; Vehicle vehicleScript; GameObject guiObj; AudioSource source; public AudioClip audio;
void Start () { vehicleScript = GetComponent(); vehicleScript.enabled = false; source = GetComponent(); guiObj = GameObject.Find("PressE"); guiObj.SetActive(false); PlayerBackup.SetActive(false); }
 // Update is called once per frame
 void OnTriggerStay(Collider other)
 {
     if (other.gameObject.tag == "Player" && inVehicle == false)
     {
         guiObj.SetActive(true);
     }
     if (other.gameObject.tag == "Player" && inVehicle == false && Input.GetKey(KeyCode.E))
     {
         source.PlayOneShot(audio, 1);
         guiObj.SetActive(false);
         PlayerBackup.SetActive(true);
         Player.SetActive(false);
         Player.transform.parent = Vehicle.transform;
         vehicleScript.enabled = true;
         inVehicle = true;
     }       
 }
 void OnTriggerExit(Collider other)
 {
     if (other.gameObject.tag == "Player")
     {
         guiObj.SetActive(false);
     }
 }
 void Update()
 {
     if (inVehicle == true && Input.GetKey(KeyCode.F))
         {
         Player.SetActive(true);
         Player.transform.parent = null;
         PlayerBackup.SetActive(false);
         vehicleScript.enabled = false;
         inVehicle = false;
         }
 }
 
               }
Answer by Landern · Aug 24, 2016 at 02:56 PM
Well on line #5 you have a public field called "Vehicle" and you apparently have a class/type called "Vehicle", you may want to change one of them(the local variable on line #5) to not confuse/conflict field/properties with Type/class names. Some of this goes to coding style and why languages are specific about how you name objects and variables so there isn't any conflict.
Answer by Doublix60 · Aug 24, 2016 at 05:32 PM
I have modified "Vehicle" (in the 5th lign (sorry for my bad english, i'm french)) but i have an other error : "error CS0246: The type or namespace name `Vehicle' could not be found. Are you missing a using directive or an assembly reference?"
Your answer