• 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 Henri 1 · Apr 02, 2011 at 03:00 AM · raycastlocalscale

Raycast Hit Distance and Local Scale error

Hi there,

Trying to resize a mesh to the appropriate size when the Raycast hits.

Script as follow:

if (RoutineRun) { var dir = Boom.transform.TransformDirection (Vector3.forward); var hit = RaycastHit; Debug.DrawRay(Boom.transform.position, dir * distance, Color.blue);

     if (Physics.Raycast (Boom.transform.position, dir,distance)) {
             Debug.Log("Boom;");
     beam.localScale = new Vector3(0.2f, 0.2f, hit.distance * 2.4f);
     }
     }

}

Keep getting 'localScale' is not a member of 'UnityEngine.GameObject'. error, and also 'distance' is not a member of 'System.Type'.

Any ideas?

EDIT:

Did declare "Distance" as follow:

var distance : float = 30;

EDIT2:

var Boom : GameObject; 
var beam : GameObject;
Boom = GameObject.Find("Boom"); 
beam = GameObject.Find("beam");

Comment
Add comment · Show 3
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 e-bonneville · Apr 02, 2011 at 03:12 AM 0
Share

Also, I just noticed http://answers.unity3d.com/questions/50077/raycast-hit-distance-and-local-scale-error is an exact duplicate. Please try to avoid duplicating questions, as this clogs up the entire system and generally isn't very nice.

avatar image Henri 1 · Apr 02, 2011 at 08:45 AM 0
Share

Something went wrong the first time I wanted to post, the "Post Question" button was greyed out, so I refreshed the page. Did flag for delete

avatar image e-bonneville · Apr 02, 2011 at 01:37 PM 0
Share

Ah, okay. You're forgiven, then. :P

2 Replies

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

Answer by Bunny83 · Apr 02, 2011 at 09:11 AM

You didn't specify the type of hit. You assigned the classtype to the hit variable. That's why hit is not of type RaycastHit but System.Type. You have to declare your variable as follows:

var hit : RaycastHit;

Can't see more errors since that's just a snippet of your code. As long as beam and Boom are defined as GameObjects and are set to valid objects it should work.


edit
You need to pass your hit variable to the Raycast function in order to get something back.

if (Physics.Raycast (Boom.transform.position, dir, hit, distance)) {
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 Henri 1 · Apr 02, 2011 at 09:25 AM 0
Share

"var hit : RaycastHit;" has been specified on the 3rd line of my code as shown in the question.

Have edited the question with the applicable code

avatar image Bunny83 · Apr 02, 2011 at 09:31 AM 0
Share

No, you had a "=" ins$$anonymous$$d of ":" that's why your variable is of type System.Type ins$$anonymous$$d of RaycastHit.

avatar image Bunny83 · Apr 02, 2011 at 09:34 AM 0
Share

Ohh, and you didn't pass your hit variable to your Raycast function. I will add that to my answer.

avatar image
1

Answer by e-bonneville · Apr 02, 2011 at 03:10 AM

First of all, you need to declare distance as a variable, probably an int or a float in your case, to avoid getting that nasty System.Type error, which (to the best of my knowledge, somebody correct me if I'm wrong) is thrown when you haven't declared a variable conflicting with a system type, and the computer grabs the system variable instead.

Secondly, replace beam.localScale with beam.transform.localScale to avoid the

'localScale' is not a member of 'UnityEngine.GameObject'

error.

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 Henri 1 · Apr 02, 2011 at 08:48 AM 0
Share

Did try the "beam.transform.localscale", but still getting the "Distance is not a member of 'System.Type'" error, although when the line is removed, the script does work, and no error messages related to the other uses of distance :(

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

No one has followed this question yet.

Related Questions

Attaching 2 objects using joints and raycasting 0 Answers

Simple AddForce Scirpt help 1 Answer

Using Trigonometry for Collision Detection 0 Answers

Get object name from raycast. 1 Answer

Make Raycast ignore anything that "Isn't" my player(Solved) 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