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 /
  • Help Room /
avatar image
0
Question by black_night · Jun 26, 2016 at 10:42 PM · error message

Two error in code CS0619 and CS1061

using UnityEngine; using System.Collections;

 public class PlayerController : MonoBehaviour 
 {    
     public float speed;
     public GUIText countText;
     public GUIText winText;
     private int count;
     private int numberOfGameObjects;
     
     void Start()
     {
         count = 0;
         SetCountText();
         winText.text = "";
         numberOfGameObjects = GameObject.FindGameObjectsWithTag("PickUp").Length;
     }
     
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
         
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         
         rigidbody.AddForce (movement * speed * Time.deltaTime);
     }
     
     void OnTriggerEnter(Collider other) 
     {
         if(other.gameObject.tag == "PickUp")
         {
             other.gameObject.SetActive(false);
             count = count + 1;
             SetCountText();
         }
     }
     
     void SetCountText ()
     {
         countText.text = "Count: " + count.ToString();
         if(count >= numberOfGameObjects)
         {
             winText.text = "YOU WIN!";
         }
     }
 }
 

Assets/Scripts/PlayerController.cs(27,17): error CS0619: UnityEngine.Component.rigidbody' is obsolete: Property rigidbody has been deprecated. Use GetComponent() instead. (UnityUpgradable)'

Assets/Scripts/PlayerController.cs(27,27): error CS1061: Type UnityEngine.Component' does not contain a definition for AddForce' and no extension method AddForce' of type UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

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
0

Answer by Aggerwal · Jun 26, 2016 at 10:46 PM

The error is tell you what is wrong, it is saying that just calling rigidbody like you did is no longer the way to do things, you should do this.getComponent<RigidBody>() or something like that instead.

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 dark-missile · Jul 02, 2016 at 09:21 AM 0
Share

hope this would help u addforce reference

avatar image
0

Answer by dark-missile · Jul 02, 2016 at 09:14 AM

yea they are right u should go to menu at top and click assets then api updater it will manually correct the script and then if this method does not work then try changing the code to

 GetComponent<Rigidbody>();
 // the code above is for c# and the code below is for unityscript or javascript:
 
 GetComponent.<Rigidbody>();

if this helped then good and for future reference check this : unity manual rigidbody component well are u indian well wanna team up with me i am making a game and have all assets which i made myself and now just need help in scripting thnx in advance if u willing to help...

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 dark-missile · Jul 02, 2016 at 09:20 AM 0
Share

hey and for that if u are using variables like add force,etc. you need to declare the variable first.like in begining write private float jumpForce,etc . and then in the error line u need to declare addforce jumpforce = ..., for future reference check this unity manual scripting addforce

 Rigidbody.AddForce
 Switch to $$anonymous$$anual
 public void AddForce(Vector3 force, Force$$anonymous$$ode mode = Force$$anonymous$$ode.Force);
 public void AddForce(Vector3 force, Force$$anonymous$$ode mode = Force$$anonymous$$ode.Force);
 Parameters
 force     Force vector in world coordinates.
 mode     Type of force to apply.
 Description
 
 Adds a force to the Rigidbody.
 
 Force is applied continuously along the direction of the force vector. Specifying the Force$$anonymous$$ode mode allows the type of force to be changed to an Acceleration, Impulse or Velocity Change. Force can be applied only to an active Rigidbody. If a GameObject is inactive, AddForce has no effect.
 
 By default the Rigidbody's state is set to awake once a force is applied, unless the force is Vector3.zero.
 
 See Also: AddForceAtPosition, AddRelativeForce, AddTorque.
 
 This example applies a forward force to the GameObject's Rigidbody.
 
 using UnityEngine;
 
 public class ExampleClass : $$anonymous$$onoBehaviour 
 {
     public float thrust;
     public Rigidbody rb;
 
     void Start() 
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate() 
     {
         rb.AddForce(transform.forward * thrust);
     }
 }
 
 public void AddForce(float x, float y, float z, Force$$anonymous$$ode mode = Force$$anonymous$$ode.Force);
 public void AddForce(float x, float y, float z, Force$$anonymous$$ode mode = Force$$anonymous$$ode.Force);
 Parameters
 x     Size of force along the world x-axis.
 y     Size of force along the world y-axis.
 z     Size of force along the world z-axis.
 mode     Type of force to apply.
 Description
 
 Adds a force to the Rigidbody.
 
 Force is applied continuously along the direction of the x,y and z vectors. Specifying the Force$$anonymous$$ode mode allows the type of force to be changed to an Acceleration, Impulse or Velocity Change. Force can be applied only to an active Rigidbody. If a GameObject is inactive, AddForce has no effect.
 
 By default the Rigidbody's state is set to awake once a force is applied, unless the force is Vector3.zero.
 
 See Also: AddForceAtPosition, AddRelativeForce, AddTorque.
 
 This example applies an Impulse force along the Z axis to the GameObject's Rigidbody.
 
 using UnityEngine;
 
 public class ExampleClass : $$anonymous$$onoBehaviour 
 {
     public float thrust;
     public Rigidbody rb;
 
     void Start() 
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate() 
     {
         rb.AddForce(0,0, thrust, Force$$anonymous$$ode.Impulse);
     }
 }
 
 

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

45 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 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

Error CS0535? 0 Answers

Roll a Ball script error?! 2 Answers

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Scene Won't Load 1 Answer

Socket: bind failed, error 3 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