2014-11-03 55 views
0

我試圖讓我的性格按下一個鍵時躲閃,但我一直歌廳這個錯誤錯誤CS1501 unity3d

CS1501:沒有重載方法Dodge' takes 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; 
    } 
} 
} 
+0

錯誤信息不清楚? '道奇方法無超載需要2個參數' – 2014-11-03 12:24:41

+2

'道奇(道奇方向目錄)'有一個參數,'道奇(道奇方向。道格,閃避);'傳遞2個參數。當你[複製/粘貼](http://answers.unity3d.com/questions/535575/have-3rd-person-make-a-side-jump.html)不正確的代碼並且不知道發生了什麼時會發生這種情況。 – Reniuz 2014-11-03 12:24:49

+0

看起來你的道奇方法需要一個參數,而在FixedUpdate方法中,你試圖傳遞兩個參數。 – gpullen 2014-11-03 12:25:55

回答

1

你被傳遞兩個參數調用Dodge方法,例如:Dodge(DodgeDirection.Forward, dodge);但你的方法只要求一個:

public void Dodge(DodgeDirection dir) 

所以爲了解決這個問題,你有兩個選擇:

  1. 只傳遞FixUpdate方法中的一個參數。
  2. 在方法的簽名上添加第二個參數。