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 Play4FreedomDE · Nov 09, 2015 at 06:24 PM · errorenter

Simple car-enter script

Again, i need help... i made myself a new script to enter and descend a car (in Unity 5), but it doesnt work... any idea where the problem is? It says that some semicolons are missing, but theyre all there.. Its hard... Any example or aid with that script would be REALLY welcome... here´s the script:

 var Cardrive = script;    //Driving script for the car
 var Cardrive = Boolean;
 function Start () { 
     Cardrive = false;
 }
 
 function Update () {
     function onTriggerEnter() {  //i have a trigger next to the car´s left front door
         animation.play() ("Enter");  //Player "enters" the car and takes place in the driver seat
         Cardrive = true;    //enables the car controlling script
     }
     if Input.GetKeyDown() ("e")      //descend the car if you press "e"
         animation.play() ("Exit") ;  //player exits the car
     Cardrive = false;   //unables the car-Script
     
 
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Nov 09, 2015 at 06:52 PM

any idea where the problem is?

Where to begin?

  var Cardrive = script;    //Driving script for the car
  var Cardrive = Boolean;

^ You have two variables of the same name. You're assigning them to values that doesn't exist. You're not defining the type of Cardrive correctly.

 function Update () {
      function onTriggerEnter() {

^ You're nesting functions. onTriggerEnter should be OnTriggerEnter.

 animation.play() ("Enter");

^ animation in Unity 5 is now a Component and not an Animation. You've mistyped Play as play. You're trying to pass an argument to a void type.

 if Input.GetKeyDown() ("e")

^ You've forgotton to use parenthesis for the if-statement. You're trying to pass an argument to a boolean type.

 animation.play() ("Exit") ;

^ Same deal as with the other animation.play issue.

  if Input.GetKeyDown() ("e")
      animation.play() ("Exit") ;
  Cardrive = false;

^ Apart from the two first lines which are syntax errors I already discussed, it looks like you got a logic error. Cardrive will always be false since you haven't used a statment block.

Apart from that, some comments make no sense. (What is "descending a car"?)

 var Cardrive : boolean;
 
 // doorKey is used to exit the vehicle.
 var doorKey = "e";
 
 private var anim : Animation;
 
 function Start () {
     Cardrive = false;
     anim = GetComponent.<Animation>();
 }
   
 function Update () {
     if (Input.GetKeyDown(doorKey))
     {
         // Player exits the car, playing an animation
         // and disabling the car controller.
         anim.Play("Exit");
         Cardrive = false;
     }
 }
  
 // I have a trigger next to the car´s left front door
 function OnTriggerEnter() { 
     // Player enters the car and takes place in the 
     // driver seat. Car controller is enabled.
     anim.Play("Enter"); 
     Cardrive = true;    
 }
Comment
Add comment · Show 6 · 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 Statement · Nov 09, 2015 at 06:59 PM 0
Share

Note that the code doesn't change any variable in any other script. If you want to set Cardrive of another script, called CarController perhaps, remove Cardrive variable and use a controller variable ins$$anonymous$$d.

 var controller : CarController;
 
 function Start() {
     controller.canDrive = false;
 }
avatar image Play4FreedomDE · Nov 11, 2015 at 07:01 PM 0
Share

Thanks for your reply, i´m new with scripting so its now wonder tha my scripts are a bit worse... i try my best but sometimes it simply doesnt work:( otherwise thanks for your help. Regards PLay4freedomDE

avatar image Statement · Nov 11, 2015 at 08:29 PM 0
Share

If you want to become a developer, just accept that it is particularly hard in the beginning. Judging from your code output, I'd recommend you try to understand two separate parts of putting together text to resemble a program.

The first part is learning what the language syntax is. Together with syntax, you should also learn to understand compiler error messages, so you better can understand what went wrong. These two are "core program$$anonymous$$g" knowledge for the language you are using (UnityScript at the moment).

The second part is learning what the API's or libraries are. This is the classes and functions that Unity have created for you to use, when accessing UnityEngine, for example. With poor understanding of syntax, you'll have problems understanding how to use the libraries.


Syntax could be simplified as the "rules" and "patterns" of text in your code, and is specific to the language you are writing in. It doesn't matter if you are using Unitys libraries or writing code from scratch.

For example if Input.Get$$anonymous$$eyDown() ("e") has two syntax errors. For example, an if-statement should be followed by parenthesis: if (Input.Get$$anonymous$$eyDown() ("e")) would be "an improvement", but it still won't compile because Input.Get$$anonymous$$eyDown() ("e") is also a syntax error and should be written as Input.Get$$anonymous$$eyDown("e"). That is correct syntax for calling a function. To put them together: if (Input.Get$$anonymous$$eyDown("e")).

Unfortunately I don't know of a good resource of learning UnityScript syntax (also called "JavaScript", but it's confusing because there is another language called JavaScript that is not UnityScript). But the learn scripting section has a video of syntax differences with C#.

There are snippets you can find here and there. If you find a good resource on UnityScript syntax, let me know.

avatar image Play4FreedomDE Statement · Nov 19, 2015 at 07:11 PM 0
Share

Thanks for your reply, Where can i learn sth like that (unity scripting basics) ? it would be nice if there would be a youtube tutorial for the basics of scripting... Thank you

avatar image Statement Play4FreedomDE · Nov 19, 2015 at 07:20 PM 0
Share

http://unity3d.com/learn/tutorials/topics/scripting

avatar image Statement · Nov 11, 2015 at 08:29 PM 0
Share

The APIs or libraries you are using can (simply) be described as "the set of classes and functions that you have at your disposal", and you can write your own APIs.

For example animation.play(); would be correct syntax, but there are two problems here as well regarding your expectations of the API. In this case there isn't any play function on animation. The property animation has been deprecated in Unity 5 (quite recently), meaning it should no longer be used. This means Unity purposefully "cancelled" that property because it is being phased out. It doesn't mean you can't use animations, but that particular identifier can't be used. Unity changed the type of the identifier to Component, which does not have a play function. But even if we did have an identifier of type Animation (defined in Unitys API), there still doesn't exist a function called play. There is one called Play, however.

You can find the entire documented API in the scripting reference, and should be where you go when you want information about how to use the API.

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

37 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Web GL Export Does Not Work in 2020.1.06b16 0 Answers

IL2CPP Windows Build 0 Answers

Library\PackageCache\com.unity.xr.legacyinputhelpers@2.0.2\Runtime\TrackedPoseDriver\TrackedPoseDriver.cs(185,13): error CS1069 0 Answers

Failed to load mono 0 Answers

WebGL Error - Max Allowed WebGL Game .zip size is 500.00 MB 1 Answer


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