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 BEES17 · Apr 15, 2016 at 02:40 PM · raycastelseeof

expecting } found Else and expecting EOF found } ???

so this code throw out both the errors specified above and i cant find any reason for it. the code it supposed to check if the ray hit something and then return what it hit or that it didnt hit anything. it is all inside the update function.

 var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 Debug.DrawRay (ray.origin, ray.direction * 10, Color.green);
 If (Input.GetMouseButtonDown (0)) {

     If (Physics.Raycast (ray, hit)) {
     print (" I am looking at " + hit.transform.name);

     }
     else {

     Print ("I am looking at nothing!");
     }
 }
Comment
Add comment · Show 1
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 tanoshimi · Apr 15, 2016 at 02:43 PM 0
Share

That's the whole script? Is this meant to be C# or JS? I've never seen any language in which "if" has a capital "I".

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dmm_jbw · Apr 15, 2016 at 03:58 PM

I'm not sure if your code doesn't compile because it's a mix of different languages, or you just typed it up with some problems. This compiles for me:

          Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
          Debug.DrawRay (ray.origin, ray.direction * 10, Color.green);
          if (Input.GetMouseButtonDown (0))
          {
              RaycastHit hit = new RaycastHit();
              if (Physics.Raycast(ray, out hit)) 
              {
                  Debug.Log(" I am looking at " + hit.transform.name);
              }
              else 
              {
                 Debug.Log("I am looking at nothing!");
              }
          }
Comment
Add comment · Show 2 · 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 BEES17 · Apr 20, 2016 at 02:12 PM 0
Share

At this point I'm going to see if something is wrong with my unity overall because i couldn't get that to run either.

avatar image NoseKills BEES17 · Apr 20, 2016 at 03:45 PM 0
Share

This code isn't supposed to run unless it's inside a .cs (C#) file and inside a class and a function...

just making sure because in these kinds of questions you can't take that for granted without more details since there's incomplete code in the original question

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Storing Renderer in a variable not working! 1 Answer

Raycasting else not working properly 0 Answers

what is EOF, found 'else' PLEASE HELP!! 1 Answer

Using Raycast and Layermask to teleport player in VR, but the Raycast teleport initiates through objects of a different layer 0 Answers

Which is more efficient - Raycasts or Physics? 2 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