Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Xavier78 · Jul 07, 2015 at 08:19 PM · 2djavascriptraycastcolliding

GetComponent() problems

So I am trying to get the size of my Collider, but it keeps giving me errors.

 #pragma strict
 
 static var CldHeadD : int[];
 static var CldLeftD : int[];
 static var CldRightD : int[];
 static var CldFeetD : int[];
 static var CldcornersD : int[];
 static var Skin : float = 0.9;
 static var Size : Vector2;
 static var tp : Vector3;
 
 function Start () {
     CldHeadD = new int[4];
     CldLeftD = new int[4];
     CldRightD = new int[4];
     CldFeetD = new int[4];
     CldcornersD = new int[4];
 }
 
 function FixedUpdate () {
     tp = transform.position;
     Size = this.GetComponent<BoxCollider2D>().size;
     for (var XU : int = 0; XU <= CldHeadD.length; XU++){ /*aray length*/
         var HitUp = Physics2D.Raycast(Vector2(/*pos.x*/tp.x + (XU - (Size.x * 0.5)) * Skin/*pos.x*/, /*pos.y*/  tp.y + (Size.y * 0.5) * Skin/*pos.y*/), Vector2.up);
         CldHeadD[XU] = HitUp.distance;/*Set distance*/
         print(CldHeadD);
     }
 }

and I get these errors.

Assets/Jorge/Scripts/Player/NEW/Colliding2.js(22,49): BCE0043: Unexpected token: ).

Assets/Jorge/Scripts/Player/NEW/Colliding2.js(22,50): BCE0044: expecting ), found '.'.

Assets/Jorge/Scripts/Player/NEW/Colliding2.js(22,51): UCE0001: ';' expected. Insert a semicolon at the end.

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

Answer by Eric5h5 · Jul 07, 2015 at 08:59 PM

You're trying to use C# syntax for GetComponent.

 size = GetComponent(BoxCollider2D).size;
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
avatar image
0

Answer by YoungDeveloper · Jul 07, 2015 at 08:23 PM

this is object - component itself and not gameobject, i believe it should be

 Size = this.gameObject.GetComponent<BoxCollider2D>().size;
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 Eric5h5 · Jul 07, 2015 at 08:59 PM 0
Share

Nope, but there's no reason to use "this" in the first place.

avatar image YoungDeveloper · Jul 07, 2015 at 09:08 PM 0
Share

i agree, i wrote in the same manner for the op and you are right about c# syntax, i guess i shouldn't be giving hints as a c# programmer lol

avatar image Bunny83 · Jul 07, 2015 at 09:32 PM 0
Share

@YoungDeveloper: No, just learn more UnityScript, even if it's just to collect arguments for why you're not using it ^^. At least that's what i do most the time :D

avatar image YoungDeveloper · Jul 07, 2015 at 09:34 PM 1
Share

@Bunny83 I know it quite well, the problem starts when i start to give advices after 14 hours of non stop program$$anonymous$$g haha, i should have seen it

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

23 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 avatar image avatar image

Related Questions

Collision isn't detected between two obects 1 Answer

Create clickable GameObjects (JS) 1 Answer

Launching a Projectile to a Raycast 1 Answer

Need Help Converting 3d Raycast Into a 2D Raycast 2 Answers

2D Jump AI Help 0 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