Gabriel Ferraz
Gabriel Ferraz

Reputation: 51

Error cs1501 unity3d

I'm trying to make my character dodge when pressing a key, but I keep geting this error

CS1501: No overload for method Dodge' takes2' arguments

here's the part of the dodging script

here's the full script, the dodge part is at the end

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;
    }
}
}

Upvotes: 0

Views: 1181

Answers (1)

Nahuel Ianni
Nahuel Ianni

Reputation: 3185

You are calling the Dodge method by passing two arguments, for example: Dodge(DodgeDirection.Forward, dodge); but your method only asks for one:

public void Dodge(DodgeDirection dir)

So in order to solve this, you have two options:

  1. Pass only one parameter in the FixUpdate method.
  2. Add a second parameter on the method's signature.

Upvotes: 1

Related Questions