- Home /
Question by
Martian_Mole · Jun 05, 2018 at 07:57 PM ·
2d2d game2d-platformercontrolaxes
How to set axes for mobile controlling?
Hello! I really need help ... I made control in my game with Axes. But then I realized that for mobile games such control is not suitable. Tell me, please, how should I proceed? (A player can only go left or right)
public class alienMove : MonoBehaviour {
public float Speed = 10f;
Rigidbody2D rb;
private bool isRight = true;
private Animator anim;
private float groundRadius = 0.2f;
void Start ()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate ()
{
anim.SetFloat("vSpeed", rb.velocity.y);
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(move));
rb.velocity = new Vector2(move * Speed, rb.velocity.y);
if(move > 0 && !isRight)
Flip();
else if(move < 0 && isRight)
Flip();
}
void Update()
{
}
void Flip()
{
isRight = !isRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Comment
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Level design clone of King of Thieves 0 Answers
Softbody physics with 2D sprites 1 Answer
How to blur 2D background sprites? 0 Answers