Unity Input Manager停止识别XBox一个触发器输入

我的2D游戏的设置类似于双杆射击游戏,但是需要将XBox控制器上的扳机向下推才能触发。在过去的几天中,触发输入工作正常,但是今天在设置了敌人之后,不再能够识别触发输入。 IF语句从未输入触发器输入控件,而且很奇怪,射击是由未在输入管理器中设置的右侧d-pad激活的。我在Mac上使用c#。如果您有任何想法请帮助。

Input Manager Settings Image:Trigger Input Settings

C#消防代码

private void FixedUpdate()
    {
        float rightx = Input.GetAxis("LookDirectionHorizontal");
        float righty = Input.GetAxis("LookDirectionVertical");
        direction = new Vector2(rightx, righty).normalized;
        angle = Mathf.Atan2(righty, rightx) * Mathf.Rad2Deg - 90f;
        firepoint.transform.eulerAngles = Vector3.forward * angle;

        if ((Input.GetAxis("FireTrigger") > 0) && Time.time > nextFire) 
        {
            Debug.Log(Input.GetAxis("FireTrigger"));

            nextFire = Time.time + fireRate;
            GameObject bullet = Instantiate(bullet1, firepoint.transform.position, firepoint.transform.rotation);

        }
    }

敌人代码

public class dinoController : MonoBehaviour
{
    public int hp = 2;
    public float speed = 2f;    // Follow speed
    public bool hasTarget = false;  // do I have a target to move towards
    public GameObject target;   // the target i want to get closer to 

    private Rigidbody2D rb;

    void Awake()
    {
        rb = gameObject.GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        if (hasTarget)
        {
            //get distance between me and my target
            float distance = Vector3.Distance(transform.position, target.transform.position);
            // am I further than 2 units away
            if (distance > 2)
            {
                // I am over 2 units away
                follow(target.transform); // do a follow
            }
        }
    }

    // if anything starts to collide with me I will run this method
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Equals("Player"))
        {    // is the other object the player
            target = collision.gameObject;      // it is so set him as my target
            hasTarget = true;   // I have a target
        }
    }

    // if something is no longer coliiding with me I will run this code
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.name.Equals("PlayerObject"))
        {
            target = null;
            hasTarget = false;
        }
    }

    private void follow(Transform target)
    {
        // add force to my rigid body to make me move
        rb.AddForce((target.transform.position - transform.position).normalized * speed);
    }
}
评论
mneque
mneque

您已使用xbox 360控制器(而不是xbox one)的输入来设置控制器。调整输入轴

https://answers.unity.com/storage/attachments/116267-xbox-one-controller-map-for-unity3d.jpg

点赞
评论