Question by
Siara23 · Jan 25, 2016 at 04:57 PM ·
touch controlsgetaxis
Replace Input.GetAxis with Touch. Is there a way of converting this:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float heroSpeed;
public float jumpForce;
public Transform groundTester;
public LayerMask layersToTest;
Animator anim;
Rigidbody2D rgdBody;
bool dirToRight = true;
private bool onTheGround = true;
private float radius = 0.1f;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
rgdBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
onTheGround = Physics2D.OverlapCircle (groundTester.position, radius, layersToTest);
float horizonatalMove = Input.GetAxis("Horizontal");
rgdBody.velocity = new Vector2 (horizonatalMove * heroSpeed, rgdBody.velocity.y);
if (Input.GetKeyDown(KeyCode.Space) && onTheGround)
{
rgdBody.AddForce (new Vector2(0f, jumpForce));
anim.SetTrigger ("jump");
}
anim.SetFloat ("speed", Mathf.Abs(horizonatalMove));
if (horizonatalMove < 0 && dirToRight)
{
Flip ();
}
if (horizonatalMove > 0 && !dirToRight)
{
Flip();
}
}
void Flip()
{
dirToRight = !dirToRight;
Vector3 BohaterScale = gameObject.transform.localScale;
BohaterScale.x *= -1;
gameObject.transform.localScale = BohaterScale;
}
}
Comment