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 Fabkins · Apr 25, 2012 at 09:15 PM · syntax

Coding technique question

Looking at the AngryBot demo I stumbled apon something I think I understand what it does but don't really know the why and what.

  1. They have the variable declaration:

      private var raycast : PerFrameRaycast;
    
    
  2. They then initialise it on awake thus:

      raycast = GetComponent.< PerFrameRaycast > ();
    
    
  3. And use it:

      var hitInfo : RaycastHit = raycast.GetHitInfo ();
    
    

So my first question is the syntax of 2). I'm not familiar with it. I'm gessing it creates an instance of the object (script) ? Looks like its a seperate thread in its own right?. I think I follow what's it doing but not 100% sure.

Secondly any good references to see what means in JS?

(grrr sorry for the constant edits the "" are messing the formatting)

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

Answer by Eric5h5 · Apr 25, 2012 at 10:18 PM

GetComponent.<PerFrameRaycast>() is the generic version of GetComponent; it works the same as C# except for slightly different syntax. However it's actually better in JS not use use generics with GetComponent, as long as you're using Unity 3.4 and later. Just do raycast = GetComponent(PerFrameRaycast). In any case, no, it has nothing to do with threads.

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 Fabkins · Apr 25, 2012 at 10:22 PM 0
Share

Ah ok. I guess I was wondering if it was its own thread instance because it was doing its own Update() but that probably shows my ignorance on the inner workings of Unity.

avatar image
0

Answer by FizzyBear · Apr 25, 2012 at 09:27 PM

 private var raycast : PerFrameRaycast;

This code just creates a raycast (a straight line within the range you've determined). But this is created per frame rather than just once (the answer is in the code you provided). You can also reference it to this link;

http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

 var hitInfo : RaycastHit = raycast.GetHitInfo ();

GetComponent means it's referencing to the inspector ingame, where ever you've assigned that script to. (whatever is in here) is the script name. You can use it in the format as:

 variablenamehere = GetComponent(Blahblahblah).avariablewithin


So you're almost correct when you're creating an instance of the object (it's just literally calling it).

When you say < xxx >, what are you referring to? Please be more specific if you can.

Hope the parts I've answered or attempted to answer helped.

Comment
Add comment · 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

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

How to declare a list of lists in JS? 2 Answers

Error in my script i don't understand. 0 Answers

[Syntax] LINQ Query Operations in UnityScript ( Js ) 1 Answer

What means "as Unity.Object" on JS-Unity syntax? 1 Answer

Are there any draw backs to using this kind of Switch statement? 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