Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重新布线的堆栈溢出错误,可能是无限循环?_C#_Unity3d - Fatal编程技术网

C# 重新布线的堆栈溢出错误,可能是无限循环?

C# 重新布线的堆栈溢出错误,可能是无限循环?,c#,unity3d,C#,Unity3d,第一篇帖子很抱歉我做错了什么 Unity告诉了我这个脚本,但没有具体说明,所有的证据都指向我的一个属性(到目前为止我看到的所有答案都有这个问题)。但我看不出是哪一个。请帮助我: 使用重新布线作为输入 using System.Collections; using System.Collections.Generic; using UnityEngine; using Rewired; public class InputManager : MonoBehaviour { public stat

第一篇帖子很抱歉我做错了什么 Unity告诉了我这个脚本,但没有具体说明,所有的证据都指向我的一个属性(到目前为止我看到的所有答案都有这个问题)。但我看不出是哪一个。请帮助我: 使用重新布线作为输入

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Rewired;

public class InputManager : MonoBehaviour
{
public static InputManager inputInstance;
[SerializeField] private int playerID = 0;
[SerializeField] public Player soldier = ReInput.players.GetPlayer(0);
[SerializeField] public Player engineer = ReInput.players.GetPlayer(1);
[SerializeField] public Player medic = ReInput.players.GetPlayer(2);
[SerializeField] public Player scout = ReInput.players.GetPlayer(3);

public enum DPadDirection
{
    Up, Down, Left, Right, Null
}

public DPadDirection dPadDir
{
    get
    {
        if(dPadUp)
        {
            return DPadDirection.Up;
        }
        else if(dPadDown)
        {
            return DPadDirection.Down;
        }
        else if(dPadLeft)
        {
            return DPadDirection.Left;
        }
        else if(dPadRight)
        {
            return DPadDirection.Right;
        }
        else
        {
            return DPadDirection.Null;
        }
    }
}

#region Controls Vars

[HideInInspector] public Vector2 movementVector
{
    get
    {
        return new Vector2(GetPlayer().GetAxis("Move Horizontal"), GetPlayer().GetAxis("Move Vertical"));
    }
}
[HideInInspector] public Vector2 lookAtOffset
{
    get
    {
        return new Vector2(GetPlayer().GetAxis("Look Horizontal"), GetPlayer().GetAxis("Look Vertical"));
    }
}

#region DPad
public bool dPadRight
{
    get
    {
        return GetPlayer().GetButtonDown("Menu Right");
    }
}

public bool dPadLeft
{
    get
    {
        return GetPlayer().GetButtonDown("Menu Left");
    }
}

public bool dPadUp
{
    get
    {
        return GetPlayer().GetButtonDown("Menu Up");
    }
}

public bool dPadDown
{
    get
    {
        return GetPlayer().GetButtonDown("Menu Down");
    }
}
#endregion

#region Shoulder Buttons
private float RTValue;
public bool isRTPressed
{
    get
    {
        return GetPlayer().GetAxis("Shoot") >= .8f ? true : false;
    }
}

private float LTValue;
public bool isLTPressed
{
    get
    {
        return GetPlayer().GetAxis("Sprint") >= .3f ? true : false;
    }
}

private float RBValue;
public bool onRBPressed
{
    get
    {
        return GetPlayer().GetButtonDown("Reload");
    }
}

private float LBValue;
public bool onLBPress
{
    get
    { //        if xV == 1  true:else:false
        return GetPlayer().GetButtonDown("Use Ability");
    }
}
#endregion

#region Other
private float backValue;
public bool onBackPress
{
    get
    {
        return GetPlayer().GetButtonDown("Open Menu");
    }
}

private float aValue;
public bool onAPress
{
    get
    {
        return GetPlayer().GetButtonDown("Menu Select");
    }

}
#endregion

#endregion

private void Awake()
{
    if (inputInstance == null)
    {
        inputInstance = this;
    }
    else
    {
        Destroy(gameObject);
    }
}

public Player GetPlayer()
{
    if(ReInput.controllers.GetLastActiveController() == soldier.controllers.GetLastActiveController())
    {
        return soldier;
    }
    if (ReInput.controllers.GetLastActiveController() == engineer.controllers.GetLastActiveController())
    {
        return engineer;
    }
    if (ReInput.controllers.GetLastActiveController() == medic.controllers.GetLastActiveController())
    {
        return medic;
    }
    if (ReInput.controllers.GetLastActiveController() == scout.controllers.GetLastActiveController())
    {
        return scout;
    }
    else
    {
        return null;
    }
}
}

提前谢谢

编辑:我修好了!问题是当我设置不同的玩家变量时。虽然我不知道为什么

[SerializeField] public Player soldier = ReInput.players.GetPlayer(0);
[SerializeField] public Player engineer = ReInput.players.GetPlayer(1);
[SerializeField] public Player medic = ReInput.players.GetPlayer(2);
[SerializeField] public Player scout = ReInput.players.GetPlayer(3);
变成

public Player soldier
{
    get
    {
        return ReInput.players.GetPlayer(0);
    }
}

[SerializeField] public Player engineer
{
    get
    {
        return ReInput.players.GetPlayer(1);
    }
}
[SerializeField] public Player medic
{
    get
    {
        return ReInput.players.GetPlayer(2);
    }
}
[SerializeField] public Player scout
{
    get
    {
        return ReInput.players.GetPlayer(3);
    }
}