Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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# 错误cs1501 unity3d_C#_Unity3d - Fatal编程技术网

C# 错误cs1501 unity3d

C# 错误cs1501 unity3d,c#,unity3d,C#,Unity3d,我试着让我的角色在按下一个键时闪避,但我一直在犯这个错误 CS1501:方法Dodge'接受2'参数时没有重载 下面是闪避脚本的一部分 这是完整的剧本,道奇部分在结尾 using UnityEngine; using System.Collections; public class player : MonoBehaviour { public int playerHP; public GUIStyle bigFont; public int attackPlayer; public in

我试着让我的角色在按下一个键时闪避,但我一直在犯这个错误

CS1501:方法
Dodge'接受
2'参数时没有重载

下面是闪避脚本的一部分

这是完整的剧本,道奇部分在结尾

using UnityEngine;
using System.Collections;

public class player : MonoBehaviour {


public int playerHP;
public GUIStyle bigFont;
public int attackPlayer;
public int defensePlayer;
public int speedPlayer;
public int atckSpeedPlayer;
public int damage;

public enum DodgeDirection { Right, Left, Forward, Backward };
public Vector3 dodge = new Vector3(5, 5, 5);

// Use this for initialization
void Start () {
    playerHP = 500;
    bigFont= new GUIStyle();
    bigFont.fontSize = 40;
    attackPlayer = 10;
    defensePlayer = 8;
    speedPlayer = 10;
    atckSpeedPlayer = 12;
}

// Update is called once per frame
void Update () {

}

void OnTriggerEnter (Collider hit){
    if(hit.tag == "swordEnemy"){
        damage = GameObject.FindWithTag("npcSamuraiNormal").GetComponent<samuraiNormalFsm>().enemyAttack - defensePlayer ;
        playerHP -= damage;
    }

}

public void OnGUI(){


    GUI.Label(new Rect(180,800,100,50), "HP:" + playerHP.ToString(), fonteGrande); //determina posiçao e transforma o valor em string

}

public void Dodge(DodgeDirection dir)
{
    switch(dir) 
    {
    case DodgeDirection.Right:
        rigidbody.AddForce(transform.right * dodge.x + transform.up * dodge.y, ForceMode.Impulse);
        break;
    case DodgeDirection.Left:
        rigidbody.AddForce(transform.right * dodge.x + transform.up * dodge.y, ForceMode.Impulse);
        break;
    case DodgeDirection.Forward:
        rigidbody.AddForce(transform.forward * dodge.z + transform.up * dodge.y, ForceMode.Impulse);
        break;
    case DodgeDirection.Backward:
        rigidbody.AddForce(transform.forward * dodge.z + transform.up * dodge.y, ForceMode.Impulse);
        break;
    }
}

void FixedUpdate()
{
    if (Input.GetKeyDown("l")){
        Dodge(DodgeDirection.Right, dodge);
    //return;
    }
    else if (Input.GetKeyDown("j")){
        Dodge(DodgeDirection.Left, dodge);
    //return;
    }
    else if (Input.GetKeyDown("i")){
        Dodge(DodgeDirection.Forward, dodge);
        //return;
    }
    else if (Input.GetKeyDown("k")){
        Dodge(DodgeDirection.Backward, dodge);
        //return;
    }
}
}
使用UnityEngine;
使用系统集合;
公共类玩家:单一行为{
公共演奏家;
公共字体;
公共int攻击播放器;
公共玩家;
公共int速度播放器;
公共int-atckSpeedPlayer;
公共财产损害;
公共枚举方向{右、左、前、后};
公共向量3道奇=新向量3(5,5,5);
//用于初始化
无效开始(){
playerHP=500;
bigFont=新的GUIStyle();
bigFont.fontSize=40;
攻击玩家=10;
防守队员=8;
speedPlayer=10;
atckSpeedPlayer=12;
}
//每帧调用一次更新
无效更新(){
}
无效对撞机(对撞机命中){
如果(hit.tag==“swordEnemy”){
伤害=GameObject.FindWithTag(“NPCSamuranNormal”).GetComponent().enemyAttack-防御玩家;
playerHP-=损坏;
}
}
公营机构{
GUI.Label(新的Rect(180800100,50),“HP:+playerp.ToString(),fonteGrande);//determina posiçao e transforma o valor em string
}
公共无效道奇(道奇方向)
{
交换机(dir)
{
方向。右:
刚体.AddForce(transform.right*dodge.x+transform.up*dodge.y,ForceMode.pulse);
打破
案例方向。左:
刚体.AddForce(transform.right*dodge.x+transform.up*dodge.y,ForceMode.pulse);
打破
前进方向:
刚体.AddForce(transform.forward*dodge.z+transform.up*dodge.y,ForceMode.pulse);
打破
大小写方向。向后:
刚体.AddForce(transform.forward*dodge.z+transform.up*dodge.y,ForceMode.pulse);
打破
}
}
void FixedUpdate()
{
if(Input.GetKeyDown(“l”)){
道奇(道奇方向。右,道奇);
//返回;
}
else if(Input.GetKeyDown(“j”)){
道奇(道奇方向。左,道奇);
//返回;
}
else if(Input.GetKeyDown(“i”)){
闪避(闪避方向、前进、闪避);
//返回;
}
else if(Input.GetKeyDown(“k”)){
闪避(闪避方向、后退、闪避);
//返回;
}
}
}

您通过传递两个参数调用
Dodge
方法,例如:
Dodge(DodgeDirection.Forward,Dodge)但您的方法只要求一个:

public void Dodge(DodgeDirection dir)
为了解决这个问题,你有两个选择:

  • FixUpdate
    方法中只传递一个参数
  • 在方法的签名上添加第二个参数

  • 错误消息不清楚<代码>方法Dodge的无重载采用2个参数
    道奇(DodgeDirection dir)
    有一个参数,
    道奇(DodgeDirection.Right,Dodge)传递2个参数。当您的代码不正确并且不知道发生了什么时,就会发生这种情况。看起来您的Dodge方法接受一个参数,而在FixeUpdate方法中,您试图传递两个参数。