• 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
Question by slader166 · Feb 11, 2013 at 10:36 PM · error

Error CS0103?

Hi,

I'm getting a CS0103 error, "The name "ballPosition" does not exist it the current context" on line 25, A.k.a: ballPostition = transform.position + new Vector3(0, 1f, 0);

Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class paddleScript : MonoBehaviour {
     
      float paddleSpeed = 10f;
      public GameObject ballPrefab;
     
     
      GameObject attachedBall = null;
     
     // Use this for initialization
     void Start () {
         
         
         
         
     SpawnBall();    
     
     }
     
     void SpawnBall() {
         //Spawns the ball, duh!
         
         ballPostition = transform.position + new Vector3(0, 1f, 0);
         Quaternion ballRotation = Quaternion.identity;    
         
         attachedBall = (GameObject)Instantiate( ballPrefab, ballPostition, ballRotation );
     }    
     
     // Update is called once per frame
     void Update () {
     
         transform.Translate ( paddleSpeed * Time.deltaTime * Input.GetAxis ( "Horizontal" ), 0, 0 );
         
         if( attachedball ) {
          attachedBall.rigidbody = transform.position + new Vector3(0, .75f, 0);    
         }    
         if( Input.GetButtonDown( "Jump" ) ){
            //Fire the ball!
            if( attachedball ) {
            attachedBall.rigidbody.isKinematic = false;        
            attachedBall.rigidbody.Addforce(0, 300f, 0);
            attachedBall = null;        
             
         }
     }
 }        
     
     
     void  OnCollisionEnter( Collision col ) {
         foreach (ContactPoint contact in col.contacts) {
         if( contact.thisCollider == collider ) {
                  float english = contact.point.x - transform.position.x;
                 
                 contact.otherCollider.rigidbody.AddForce( 300f * english, 0, 0);
             }
             
         }
     }    
 }
 
Comment
Starkid225

People who like this

1 Show 0
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

Answer by EHogger · Feb 12, 2013 at 12:12 AM

Variables in c# have to be declared as a certain type before they can be assigned. You need to add something like:

 private Vector3 ballPosition;
 private Quaternion ballRotation;
 

In the same place that you (correctly) declared ballPrefab and attachedBall.

Comment
Dave-Carlile

People who like this

1 Show 0 · 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

Answer by slader166 · Feb 14, 2013 at 03:04 AM

Sorry, I'm used to javascript. Where exactly would I add those? From what I can tell I declared those at line 25 and line 5.

Comment

People who like this

0 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 flaviusxvii · Feb 14, 2013 at 04:17 AM 0
Share

I think you meant to comment on EHoggers answer. Please make sure you comment next time.. You can put those variables anywhere in the class, outside of any methods. It's customary to put them right after the opening bracket of the class.

avatar image slader166 · Feb 16, 2013 at 11:55 PM 0
Share

I added it to line 26 and I am getting another error, unexpected symbol "private".

avatar image Starkid225 · Feb 16, 2013 at 11:59 PM 0
Share

They must be placed before you try to use them. Try placing them on line 5.

avatar image slader166 · Feb 17, 2013 at 12:07 AM 0
Share

I fixed the errors, I spelled it "postition" instead of "position", LOL. But I am getting a new error: paddleScript.cs(41,31): error CS0200: Property or indexer `UnityEngine.GameObject.rigidbody' cannot be assigned to (it is read only). How do I fix that?

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

12 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

Related Questions

Camera annoying error helps error 1 Answer

Unity WebPlayer does not install. 1 Answer

I can't fix this error! 1 Answer

error CS1502 and error CS1503 What is this? 1 Answer

Problem with gun/shooting scripting 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