Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity script error

Discussion in 'Scripting' started by halojman, Mar 17, 2016.

  1. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    Hello, I'm currently trying to create a melee scrip, but I've ran into an error. Can someone help me fix it?

    This is my error:

    "

    Assets/MeleeSystem.js(8,37): BCE0017: The best overload for the method 'UnityEngine.Input.GetMouseButtonDown(int)' is not compatible with the argument list '(String)'.

    "

    This is my script:

    "
    #pragmastrict

    var TheDamage : int = 50;
    var Distance : float;

    function update ()
    {
    if (Input.GetMouseButtonDown("Fire1"))
    {
    var hit : RaycastHit;
    if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
    {
    Distance = hit.distance;
    hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
    }
    }
    }

    "
    I'm using JavaScript.
     
  2. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    did you try Input.GetButtonDown("Fire1")

    other wise you need to use an Int in your code
    if (Input.GetMouseButtonDown(0))
    if (Input.GetMouseButtonDown(1))
     
    halojman likes this.
  3. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    halojman likes this.
  4. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    Thanks, but I've already fixed the problem!