- Home /
Question by
sir_hefner · Mar 22, 2014 at 08:33 PM ·
androidrigidbodyjump
creating 2d side scroller for android cant get my player to jump help skl project
im trying to get my player to jump once i tap the jump button i have used prefab touch pads ive tried various ways to get this to work i have now set a script on the texture of the button its self to respond to when the user taps for jump but my character does nothing. here's my jump script plz sum1 help i aint gt long left!
using UnityEngine; using System.Collections;
public class jump : MonoBehaviour { private float jumpTime = 0.0f; public float speed = 2f; public float jumpForce = 50f; public float maxJumpVelocity = 2f; public float minJumpDelay = 0.5f; public GUITexture targetTex; public Texture2D touchTex; public Texture2D normalTex; // Use this for initialization void Start () { targetTex.texture = touchTex; }
// Update is called once per frame
void Update ()
{
Touch touch;
if(Input.touchCount > 0 )
{
touch = Input.touches[0];
if(targetTex.HitTest(touch.position))
{
if (touch.phase == TouchPhase.Began)
{
if(jumpTime > 0)
{
jumpTime -= Time.deltaTime;
if (touch.phase == TouchPhase.Began)
{
rigidbody2D.AddForce(transform.up * jumpForce);
jumpTime = minJumpDelay;
}
}
}
}
}
}
}
Comment
Your answer