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 XSSA · Aug 16, 2012 at 04:08 AM · javascripterrorraycastspace

Problem with hitInfo in Raycast.

So i have this script that is trying to find which star you've clicked on and then set some variables with it properties.

Move.js

     var moveSpeed = 1;
     var turnSpeed = 1;
     var sscale;
     var stempscale;
     var speed : String;
     var object : String;
     var rayLength;
     var d;
     var loc : Vector3;
     var obj1 : Transform;
     var obj2 : Transform;
     var yloc : Vector3;
     
     function Update () 
     {
         if(Input.GetButton("Forward"))
         {
             transform.position += transform.forward * moveSpeed * Time.deltaTime;
         }
         
         if(Input.GetButton("Backward"))
         {
             transform.position += -transform.forward * moveSpeed * Time.deltaTime;
         }
         
         if(Input.GetButton("Left"))
         {
             transform.position += -transform.right * moveSpeed * Time.deltaTime;
         }
         
         if(Input.GetButton("Right"))
         {
             transform.position += transform.right * moveSpeed * Time.deltaTime;
         }
         
         if(Input.GetButton("rForward"))
         {
             transform.eulerAngles.x -= turnSpeed * Time.deltaTime;
         }
         
         if(Input.GetButton("rBackward"))
         {
             transform.eulerAngles.x += turnSpeed * Time.deltaTime;
         }
         
         if(Input.GetButton("rLeft"))
         {
             transform.eulerAngles.y -= turnSpeed * Time.deltaTime;
         }
         
         if(Input.GetButton("rRight"))
         {
             transform.eulerAngles.y += turnSpeed * Time.deltaTime;
         }
     
     // find your position    
         yloc = transform.position;
     
     //for speed control
         if (Input.GetButtonDown ("e")) {
         moveSpeed = 1;
         turnSpeed = 25;
         speed = "Slow";
         }
         if (Input.GetButtonDown ("r")) {
         moveSpeed = 5;
         turnSpeed = 50;
         speed = "Normal";
         }
         if (Input.GetButtonDown ("t")) {
         moveSpeed = 10;
         turnSpeed = 75;
         speed = "Fast";
         }
         
     // for star selecting    
         rayLength = 10;
         if (Input.GetMouseButton(0)) {
 //PROBLEM IS HERE -- (I have also tried it without " : RaycastHit" on the end) -- vvv    
             if (Physics.Raycast(transform.position, -Vector3.forward , out HitInfo : RaycastHit , rayLength)) {
                 object = RaycastHit.transform;
                 obj2 = RaycastHit.transform;
                 loc = RaycastHit.transform.position;
             }
         }
         d = Vector3.Distance(obj1.position, obj2.position);
     }
     
     
     function OnGUI ()
     {
     if(Input.GetButton("Dcontrols"))
         {
         GUILayout.Label("Speed: " + speed);
         GUILayout.Label("Display Controls: Q" );
         GUILayout.Label("Forward: UP Arrow");
         GUILayout.Label("Backward: DOWN Arrow");
         GUILayout.Label("Left: LEFT Arrow");
         GUILayout.Label("Right: RIGHT Arrow");
         GUILayout.Label("Rotate Up: W");
         GUILayout.Label("Rotate Down: S");
         GUILayout.Label("Rotate Left: A");
         GUILayout.Label("Rotate Right: D");
         }
     else{
         GUILayout.Label("Display Controls: Q (Hold Down)");
         GUILayout.Label("Speed: " + speed);
         GUILayout.Label("Your Location: " + yloc);
         GUILayout.Label("Star Name: " + object);
         GUILayout.Label("D to Sun: " + d + "ly");
         GUILayout.Label("Locaton: " + loc);
         }
     }

But it returns the error:

Assets/STARS/move.js(79,80): BCE0044: expecting ), found 'HitInfo'.

Assets/STARS/move.js(79,88): BCE0044: expecting ), found ':'.

Assets/STARS/move.js(79,90): BCE0043: Unexpected token: RaycastHit.

Assets/STARS/move.js(79,112): BCE0043: Unexpected token: ).

I just don't get what is going on...

And when i remove it all together it has these errors:

Assets/STARS/move.js(80,45): BCE0020: An instance of type 'UnityEngine.RaycastHit' is required to access non static member 'transform'.

Assets/STARS/move.js(81,43): BCE0020: An instance of type 'UnityEngine.RaycastHit' is required to access non static member 'transform'.

Assets/STARS/move.js(82,42): BCE0020: An instance of type 'UnityEngine.RaycastHit' is required to access non static member 'transform'.

Make sense because i dont have it...

So any suggestions??

Thanks in advance for your help.

Its probably just a lowercase that needs to be uppercase....

If you need to know anything else then tell me.

"Onwards and Upwards my friend!!!" - Doctor Whooves

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
Best Answer

Answer by superbsumit · Aug 16, 2012 at 05:37 AM

 var HitInfo : RaycastHit;
 if (Input.GetMouseButton(0)) { 
 if (Physics.Raycast(transform.position, -Vector3.forward ,HitInfo, rayLength)) {
              object = HitInfo.transform.gameObject.name;
              obj2 = HitInfo.transform;
              loc = HitInfo.transform.position;
 }}
Comment
Add comment · Show 5 · 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 fafase · Aug 16, 2012 at 05:38 AM 0
Share

This is @Dave A.'s answer with my comment.

avatar image DaveA · Aug 16, 2012 at 06:29 AM 0
Share

Hmmmmmmmmm

avatar image XSSA · Aug 16, 2012 at 07:00 AM 0
Share

hmmmmmmmm what?

avatar image fafase · Aug 16, 2012 at 07:22 AM 0
Share

Nothing bad, just the fact that it is not his own answer but a collection of others. All in all, I don't think Dave really needs more karma to prove anything and personally I do not care much about it either. And you got your thing working which is the main purpose.

avatar image DaveA · Aug 17, 2012 at 06:51 PM 0
Share

Yes that's true.

avatar image
0

Answer by DaveA · Aug 16, 2012 at 04:11 AM

 var HitInfo : RaycastHit;
 if (Physics.Raycast(transform.position, -Vector3.forward , out HitInfo, rayLength)) 
Comment
Add comment · Show 3 · 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 XSSA · Aug 16, 2012 at 04:16 AM 0
Share

errors:

Assets/STARS/move.js(80,80): BCE0044: expecting ), found 'HitInfo'.

Assets/STARS/move.js(80,88): BCE0044: expecting ), found ','.

Assets/STARS/move.js(80,90): BCE0043: Unexpected token: rayLength.

Assets/STARS/move.js(81,32): BCE0044: expecting :, found '='.

avatar image fafase · Aug 16, 2012 at 04:37 AM 0
Share
 var HitInfo : RaycastHit;
 if (Physics.Raycast(transform.position, -Vector3.forward ,HitInfo, rayLength))

out is to be removed in front of HitInfo.Then in your script all Raycast.something should be changed for HitInfo.something

avatar image XSSA · Aug 16, 2012 at 05:38 AM 0
Share

It works!!!!!

"yesyeysyesyeysyes! YEEEESSS!!!!" - Twilight Sparkle

Thank You fafase!

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

11 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

Related Questions

I need help with Javascript 1 Answer

Javascript Object reference not set to instance of an object - Raycasting 0 Answers

Raycasting in script suddenly stopped working 1 Answer

im having trouble with raycast shooting script 0 Answers

GetComponent() problems 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