My 2d character controller works on horizontal movement when I stop on a slope it slides back down…
using UnityEngine;
using System.Collections;
public class movementScript : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
public AudioClip jump;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.1f;
public LayerMask whatIsGround;
public float jumpForce = 700f;
void Start () {
anim = GetComponent<Animator>();
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool ("Ground", grounded);
anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if(move > 0 &&!facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Update(){
if (grounded && Input.GetKeyDown(KeyCode.UpArrow)){
anim.SetBool ("Ground", false);
rigidbody2D.AddForce(new Vector2(0, jumpForce));
if(Input.GetKeyDown(KeyCode.UpArrow)){
if(!audio.isPlaying){
audio.clip = jump;
audio.Play ();
}
}
}
}
void Flip(){
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}