Basic Movement on 2D (C#)

Hello, this is mi first time posting on this community as I installed and I ve been working working on Unity since yesterday. I started my first project which involves a character moving around some simple stage, like every platform game we know. The issue is, I ve been having some trouble with the code of the script referred to the basic movement of my character (moving and jumping properly). Despite being quite similar to Java, the programming language I know, I got some doubts about using C# on Unity.

For example, I got this character I told you, which is an animation (made with sprites) but obviously the animation never stops, its looping all the time. I’ve thought to make it stop when the character’s not moving, or to change it when he’s jumping but I don’t really know how to make REFERENCE to my character. I mean, I don’t know how to do something like this:



 //Or it could be   myCharacter.setSprite("Jump");


It’s difficult to me to see what my character is, and how to refer it inside my code.
Same thing happens when I want to know if he’s moving or not.

By the moment my codes just allows my character to move around the sceneraio without following mechanic’s laws, as he can jump infinitely and falls really slow. He moves really fast as well… here’s the few lines I could write:

using UnityEngine;
using System.Collections;

public class Movimiento1 : MonoBehaviour {

	public Vector2 speed = new Vector2(50,50); 
	private Vector2 velocity;

	void Update () {
		float inputX = 0;
                float inputY = 0;
		inputX = Input.GetAxis("Horizontal");
		inputY = Input.GetAxis("Vertical");
		//Ahora muevo segun la direccion
		// I already got the module(speed vector) and now I got the direction represented with the variables inputX and inputY, 
		//so now i cant mae the velocity vector:
		velocity = new Vector2(speed.x * inputX, speed.y * inputY);		
	void FixedUpdate() {
		rigidbody2D.velocity = velocity;


In summary, my concerns are mainly referred to making reference to an specific GameObject in order to know it’s actual variables, such as the Transform ones.

Sorry for my engish(i’m not a native speaker) and thank you in advance!

If you want to know the transform variables of a object you want to collide with in the game.
Then, Add box colliders to both your character and the platform it wants to collide with.

Attach this code to your player Game object and insert desired values for speed and jump:

and, Attach this one to your Platforms (ground on which the player/character will stand):