Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Problema en este Script

Iniciado por SuperMax, Julio 24, 2015, 12:08:02 AM

Tema anterior - Siguiente tema
Hola buenas. Estoy intentando crear un movimiento de un player al apretar unos botones que he creado. Pues bien, he modificado un codigo de Devin Curry porque él solo hizo que el player se pueda mover en Horizontal, y yo lo he modificado que también se pueda para vertical. El problema está en que al apretar los botones para que se mueva horizontal, va sin problemas, pero a la hora de hacerlo con los verticales, el player en vez de moverse y pararse cuando yo los suelto, no para (osea que sigue al infinito y más alla) Y he probado a hacer muchas modificaciones pero no hay manera. A ver si he cambiado mal el código o algo. 
using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
public float speed = 10;
public LayerMask playerMask;
public bool canMoveInAir = true;
Transform myTrans;
Rigidbody2D myBody;

float hInputhz = 0;
float hInputvt = 0;


void Start ()
{
   //  myBody = this.rigidbody2D;//Unity 4.6-
   myBody = this.GetComponent<Rigidbody2D>();//Unity 5+
   myTrans = this.transform;

}

void FixedUpdate ()
{

   
   #if !UNITY_ANDROID && !UNITY_IPHONE && !UNITY_BLACKBERRY && !UNITY_WINRT || UNITY_EDITOR
   //Move(Input.GetAxisRaw("Horizontal"));
   //Move2 (Input.GetAxisRaw("Vertical"));

   #else
   Move (hInput);
   #endif

   Move (hInputhz);
   Move2 (hInputvt);

}

void Move(float horizonalInput)
{

   
   Vector2 moveVel = myBody.velocity;
   moveVel.x = horizonalInput * speed;
   myBody.velocity = moveVel;
}
void Move2(float verticalInput)
{
   Vector2 moveVel = myBody.velocity;
   moveVel.y = verticalInput * speed;
   myBody.velocity = moveVel;
}



public void StartMovingHz(float horizonalInput)
{
   hInputhz = horizonalInput;
}

public void StartMovingVt(float verticalInput)
{
   hInputvt = verticalInput;
}


}
 
Vale, ya lo he solucionado. A ver si consigo borrar este Post, xD.


Etiquetas: