UnityEngine.Component problems???

Hi

I’m studying some tutorials on move an object by clicks of the mouse on screen with left button.

I’m using Unity 5 and MonoDevelop 4.0.1 to test scripts and gives me always this error when I run debugging: " **UnityEngine.Component not contain a definition for velocity and could not find any method extension of accepting a first argument … "**Translated from Portuguese to English (sorry). Can anyone help me?

This is the code in C # I’m testing:

public class MouseController : MonoBehaviour {



	// Use this for initialization
	void Start () 
	{
	}

	public float jetpackForce = 75.0f; 
	public float forwardMovementSpeed = 3.0f;

	void FixedUpdate () 
	{


		bool jetpackActive = Input.GetButton("Fire1");
		
		if (jetpackActive) {
			GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, jetpackForce));
		
		} 

		Vector2 newVelocity = rigidbody2D.velocity;
		newVelocity.x = forwardMovementSpeed;
		rigidbody2D.velocity = newVelocity;
	
	}


	// Update is called once per frame
	void Update () {
		
	}

}

Good thing @BoredMormon posted a video about this here.

The issue you’re having is on 24, rigidbody2D isn’t a thing in your script. Watch the video, check out this source below and see if it helps.

public class MouseController : MonoBehaviour {
	public float jetpackForce = 75.0f; 
	public float forwardMovementSpeed = 3.0f;

	// Use this for initialization
	void Start () {
	}
	
	void FixedUpdate () 
	{
		bool jetpackActive = Input.GetButton("Fire1");
		RigidBody2D rb2d = GetComponent<Rigidbody2D>(); // Just got and stored a local reference to the attached component RigidBody2D
		
		if (jetpackActive) {
			rb2d.AddForce (new Vector2 (0, jetpackForce));
		} 

		Vector2 newVelocity = rb2d.velocity; // use reference to rigidbody2d that is on this gameobject
		newVelocity.x = forwardMovementSpeed; // update the vector2 struct
		rb2d.velocity = newVelocity; // replace velocity on rigidbody2d
	}

	// Update is called once per frame
	void Update () {
	}
}