Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Doublix60 · Aug 24, 2016 at 02:23 PM · scripting problemboat

error CS0118: `EnterVehicle.Vehicle' is a `field' but a `type' was expected

alt textI 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;
         }
 }

}

9.png (122.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

MSDN c# coding guidelines

Big'ol list on Stack

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Doublix60 · Aug 25, 2016 at 08:39 AM 0
Share

pls help me :/

avatar image
0

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?"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem with a ship controller script 1 Answer

Problem with boat script 0 Answers

Hi, we are currently doing our thesis, it's a quiz type of game. My question is, how do I collect the scores from four different scripts and output them on the menu page? 0 Answers

Hai guys i need help why my scripts not running "i will make button next3dobject and prev3dobject" 1 Answer

Crazy Construction Destruction of GameObjects 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges