Hello i have problem, player moves automatically with constant speed but when he fall, he fall with same speed, how do i stop speed movement in air and when he hit ground he will continue to move with speed before. Ty. Here is the code …
using UnityEngine;
using System.Collections;
public class playerBehavior : MonoBehaviour
{
public float speedUnity;
float speed;
bool facingRight;
bool facingLeft;
Animator anim;
Rigidbody2D rb;
void Start ()
{
anim = GetComponent<Animator> ();
rb = GetComponent<Rigidbody2D> ();
facingRight = true;
facingLeft = false;
}
// Update is called once per frame
void Update ()
{
MovePlayer (speed);
if(facingRight)
{
speed = speedUnity;
}
if(!facingRight)
{
speed = -speedUnity;
}
}
void MovePlayer(float sendedSpeed)
{
if(sendedSpeed > 0)
{
rb.velocity = new Vector3(speed, rb.velocity.y, 0);
}else
{
rb.velocity = new Vector3(speed, rb.velocity.y, 0);
}
}