• 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 /
avatar image
0
Question by JimRoot · Nov 06, 2013 at 06:45 PM · javascriptconvertc#

Javascript Error: BCE044 and BCE043

Hey Guys! I have a problem, I usualy just doing C# Coding and have to switch now to JS. my first experiment is to turn a "click on a mesh via raycasting and then something will happen" script into from a C# script to a JS Script. the JS code currently looks like this:

  //import UnityEngine;
 //import System.Collections;
 
 class carenter extends MonoBehaviour {
 
     // Use this for initialization
     function Start () : void {
     
     }
     
     // Update is called once per frame
     function Update () : void {
      var screenRay : Ray= Camera.main.ScreenPointToRay(ScreenTouchPosition);
      var rayhit : RaycastHit;
     if(Physics.Raycast(screenRay,  rayhit : out  )){
     if(rayhit.collider.tag == "doorTriggerLeft"){ //whatever you want to call it
         Debug.Log("Driving");
     }
 }

i know that this should be the C# code:

 Ray screenRay = Camera.main.ScreenPointToRay(ScreenTouchPosition);
 RaycastHit rayhit;
 if(Physics.Raycast(screenRay, out rayhit)){
     if(rayhit.collider.tag == "CoorTriggerLeft"){ //whatever you want to call it
         Debug.Log("Driving");
     }

but my JS Code is just giving me these errors: Assets/car enter.js(15,47): BCE0044: expecting ), found ':'. Assets/car enter.js(15,49): BCE0044: expecting ), found 'out'. Assets/car enter.js(15,54): BCE0043: Unexpected token: ). Assets/car enter.js(20,1): BCE0044: expecting }, found ''. Assets/car enter.js(20,1): BCE0044: expecting }, found ''.

Could you guys please help me out with that?

Comment
Add comment · Show 2
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 Professor Snake · Nov 06, 2013 at 07:39 PM 0
Share

I'm pretty sure you don't really need to specify that rayhit is an output since everything in Javascript works like a pointer. Replace rayhit : out with rayhit.

avatar image Eric5h5 · Nov 06, 2013 at 07:46 PM 0
Share

Not everything works like a pointer. Structs and primitive types are by value, unless explicitly passed by reference with "out" or "ref", which can only be done in C# scripts. That is, C# scripts can define ref or out parameters, which can be used in Unityscript, but you can't declare them in Unityscript functions.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Nov 06, 2013 at 07:46 PM

Remove "out"; you don't specify "out" or "ref" in Unityscript (also out and ref aren't types). Also remove the class definition, since scripts in Unityscript are automatically classes that extend MonoBehaviour anyway. (Not that it's related to C#/Unityscript conversion, but it's better to use the CompareTag function, instead of using string comparisons with ==.)

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 JimRoot · Nov 06, 2013 at 08:45 PM 0
Share

cool, thanks. worked out good and the code looks like that:

  //import UnityEngine;
 //import System.Collections;
 
 class carenter extends $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     function Start () : void {
     
     }
     
     // Update is called once per frame
     function Update () : void {
      var screenRay : Ray= Camera.main.ScreenPointToRay(ScreenTouchPosition);
      var rayhit : RaycastHit;
     if(Physics.Raycast(screenRay,  rayhit));
     if(rayhit.collider.tag == "doorTriggerLeft");
         Debug.Log("Driving");
     }
 }

but still i have 1 (new) error: Assets/car enter.js(13,59): BCE0005: $$anonymous$$ identifier: 'ScreenTouchPosition'.

can you tell me whats wrong with that?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Can't make unity connect to SQLite database 1 Answer

Disable script from code 5 Answers

Grid Based Movement (Pokemon-like) 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