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?)
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.
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...
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
Follow this Question
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