Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by sacajawhoohoo · Mar 20, 2014 at 01:10 AM · errorraycastnot working

Raycast Having Pointless Errors

 private var enter : boolean;
 var myAudioClip: AudioClip[];
 var mySkin : GUISkin;
 
 function Update ()
 {
     if(Input.GetMouseButtonDown(0) && enter)
     {
         Ray = camera.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast (ray, out hit3, 5.0f))
         {
             if(audio.mute)
             audio.mute = false;
             else
             audio.mute = true;
         }
     }
 }
 
 function OnGUI()
 {
     GUI.skin = mySkin;
     if(enter)
     {
         GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 200, 200), "do whatever");
     }
 }

This is getting errors with just line 10, saying that the Unexpected token: 5.0f. and
BCE0044: expecting ), found ',' and finally BCE0044: expecting ), found 'hit3'

What is the issue, those shouldn't be errors, they should be there? Why is it considering them errors?

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 robertbu · Mar 20, 2014 at 01:13 AM 0
Share

Get rid of the 'out'. Not used in Javascript.

avatar image sacajawhoohoo · Mar 20, 2014 at 01:50 AM 0
Share

that fixes the issues, but now it says that BCE0049: Expression 'Ray' cannot be assigned to. BCE0005: $$anonymous$$ identifier: 'ray'. and BCE0005: $$anonymous$$ identifier: 'hit3'. ???

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Nition · Mar 20, 2014 at 02:29 AM

Your issues were:

  • "out" isn't needed in UnityScript

  • "f" on floats isn't needed in UnityScript

  • "ray" was never defined, only "Ray", which was the type you needed but not a variable in itself

  • "hit3" was never defined

Make sure you carefully read error messages, as they'll usually give you a good idea of what's wrong. If it says "Unknown identifier: 'ray'.", then ray mustn't have been defined somewhere. You can double-click the messages to go straight to where the error occurred.

Fixed version:

 function Update ()
 {
     if(Input.GetMouseButtonDown(0) && enter)
     {
        var ray : Ray = camera.ScreenPointToRay(Input.mousePosition);
        var hit3 : RaycastHit;
        if (Physics.Raycast(ray, hit3, 5.0))
        {
          if(audio.mute)
          audio.mute = false;
          else
          audio.mute = true;
        }
     }
 }
Comment
Add comment · Show 4 · 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 sacajawhoohoo · Mar 20, 2014 at 02:49 AM 0
Share

well, now im getting no errors, but it does not work? maybe im using the wrong colliders? its a box collider and it dosnt work if its a trigger or not

avatar image Nition · Mar 20, 2014 at 02:55 AM 0
Share

You can use Debug.DrawRay to check which direction the ray is really going.

$$anonymous$$aybe the box is more than 5m away? You could check the ray's direction AND length with something like:

 Debug.DrawLine(ray.origin, 5.0 * ray.direction, Color.green, 10.0f);
avatar image sacajawhoohoo · Mar 20, 2014 at 04:55 AM 0
Share

didnt show up, maybe im putting the script on the wrong object?

avatar image Nition · Mar 20, 2014 at 08:35 AM 0
Share

It shouldn't matter which object it's attached to really. Chuck a print("something"); line inside your If statement and make sure it's actually being called.

I think you also need the Gizmos button turned on to see Debug stuff.

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

21 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

Related Questions

Raycast hits and affects all items within the same tag 2 Answers

Raycast doesn't update 1 Answer

Unity 3.4.0 Running really slow 1 Answer

Raycasting in script suddenly stopped working 1 Answer

GameObject[] Issues 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