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 itsTripp · May 18, 2014 at 02:50 AM · programming-basics

Help converting js to C# from Brackey's tutorial.

I've been watching the Brackey's pong tutorials on youTube and I have been trying to convert his javascript to C#. I've done excellent up until this portion. Any help is appreciated. Video Link: Brackey's Pong Tutorial Link

 void Update () {
         var xVel : float = rigidbody2D.velocity.x;
         if (xVel < 18 && xVel > -18 && xVel != 0) {
             if (xVel > 0) {
                 rigidbody2D.velocity.x = 20;
             }
             else {
                 rigidbody2D.velocity.x = -20;
             }
         }
     }


Comment
Add comment · Show 2
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 itsTripp · May 18, 2014 at 03:53 AM 0
Share

I tried changing

 float xVel = rigidbody2D.velocity.x;

before posting, thinking that was my problem. but

 { rigidbody2D.velocity = new Vector2(20, rigidbody2D.velocity.y); }

 

was where I was having my problems. I wasn't thinking that I had to define a rigidbody2D.velocity.y.

Thank you a ton.

avatar image mattyman174 · May 18, 2014 at 04:11 AM 0
Share

Can you please accept the answer below as correct just to close this Question, thanks.

2 Replies

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

Answer by mattyman174 · May 18, 2014 at 02:55 AM

 void Update()
     {
         float xVel = rigidbody2D.velocity.x;
 
         if (xVel < 18 && xVel > -18 && xVel != 0)
         {
             if (xVel > 0)
             {
                 rigidbody2D.velocity = new Vector2(20, rigidbody2D.velocity.y);
             }
             else
             {
                 rigidbody2D.velocity = new Vector2(-20, rigidbody2D.velocity.y);
             }
         }
     }

That what your after?

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 rgowen · May 18, 2014 at 03:07 AM

The only line you should have to change is this one:

 var xVel : float = rigidbody2D.velocity.x;

As C# is a strongly typed language, you just use the format type variableName = value, like this:

 float xVel = rigidbody2D.velocity.x;


I'd really suggest that you learn how to translate back and forth, especially if you're going to follow along with tutorials. A little goes a long way with that, as there seems to be a fairly equal distribution of people who use C# or JavaScript. If anything, it seems there are more people that use JavaScript.

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

22 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

Related Questions

Referencing variables / functions on another script 1 Answer

Block programming for Kid 1 Answer

Which programs should i use for programming a game? 1 Answer

How to find Gameobject with given coordinates 1 Answer

Rotate function on c# 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