Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DarkSealer · Nov 23, 2015 at 08:18 PM · errorcs0117cs0120

BlockBreaker Tutorial: CS0120 Error.

 using UnityEngine;
 using System.Collections;
 
 public class Ball : MonoBehaviour {
 
     public Paddle paddle;
     private Vector3 paddleToBallVector;
     private bool hasStarted = false;
 
 
     // Use this for initialization
     void Start () {
         paddleToBallVector = this.transform.position - paddle.transform.position;
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (!hasStarted) {
             this.transform.position = paddle.transform.position + paddleToBallVector;
 
             if (Input.GetMouseButtonDown (0)) {
             print ("Mouse Clicked, launch ball.");
             hasStarted = true;
             Ball.rigidbody2D.velocity = new Vector2(2f, 10f);
             }
         }
     }
 }
 

It seems that there is something wrong in my Ball.rigidbody2D.velocity = new Vector2(2f,10f); line (CS0120) and I have no idea. The guys who made that tutorial has no problem there, but I've got "velocity" with red, telling me it has no definition for "velocity" (error CS0117) ... Any ideas?

The line is 26 (26, 30).

Comment
Add comment · Show 4
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 gjf · Nov 23, 2015 at 05:34 PM 0
Share

it's quite likely that the tutorial was made using an earlier version of unity which contained a shortcut for rigidbody2D.... those have been removed for the more recent versions so you'll need to get the component yourself before accessing. the unity docs/tutorials should show you how.

in future, to help people helping you, please post the complete error message including line numbers.

avatar image DarkSealer gjf · Nov 23, 2015 at 06:14 PM 0
Share

the tutorial was made with unity 4.6, so... I guess it should work. Well... at first I had one more error because ins$$anonymous$$d of Ball.rigidbody2D... was this.rigidbody2D... so I changed that and that error was solved, but this one...

The line is 26 (26, 30).

avatar image gjf DarkSealer · Nov 23, 2015 at 06:52 PM 1
Share

" I guess it should work"... no! unless you're running the same version, assume nothing ;) and if you're running 5.x - then it will NOT work.

there's no rigidbody2D variable defined within the Ball class - which is what line 26 specifies.

if this script is attached to the ball then you don't need to do anything but get the Rigidbody2D component and refer to it... so something like:

 gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(2f, 10f);

although you should cache the component reference in Awake()/Start() to avoid doing it every time.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Error CS0117 1 Answer

Unity iPhone - StreamReader.EndOfStream Not Working? 1 Answer

error CS0117: `Resources' does not contain a definition for `Load' 1 Answer

Unity doesn't recognize any definition for Network 1 Answer

Help with more code 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