Android环境下getaxis怎么用,c# - Input.GetAxis for android - Stack Overflow

I'm creating a maze game and curently i am having delays with my android controls. I have lade the computer controls to move front and to turn left and right and to jump using input.getaxis. Now on android i created buttons that work but not how i want. It can jump and turn how i want but it doesnt move properly. There are 2 problems one is that when i click it moves a bit and then i need to click again but i want to hold and it will move continuously and second problem is that when i turn the character doesnt move the corect way it goes always on x axis with input.getaxis everything works perfectly but i need something that will work for androdid like that, here is my code:

using UnityEngine;

using System.Collections;

public class PlayerMovement : MonoBehaviour {

public float speed;

public float speedj;

Rigidbody rb;

static Animator anim;

void Start()

{

rb = GetComponent();

anim = GetComponent();

}

public void Walk ()

{

anim.SetTrigger ("Walk");

rb.velocity = new Vector3 (0,0,7f);

}

public void Left ()

{

transform.Rotate(0,-90f,0);

}

public void Right ()

{

transform.Rotate(0,90f,0);

}

public void Jump ()

{

anim.SetTrigger ("Jump");

rb.velocity = new Vector3 (0,4f,0);

}

public void StopVelocity ()

{

rb.velocity = Vector3.zero;

transform.Translate(0,0,0);

}

void FixedUpdate ()

{

float x = Input.GetAxis ("Horizontal") * Time.deltaTime * speed;

float z = Input.GetAxis ("Vertical") * Time.deltaTime * speed;

transform.Translate (0,0,z);

transform.Rotate (0,x,0);

if(Input.GetKey(KeyCode.Space))

{

anim.SetTrigger ("Jump");

rb.velocity = new Vector3 (0,speedj,0);

}

}

}

So this is it the fixedUpdate functionis for the computer the others are for buttons for android i am using event trigger for pointer up and down events pleasehelp me to change the code so that it will work for android like it works with Input.getAxis for computer thanks!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值