Problems Getting My Control Script To Work

Hello everyone.

I am so sorry. I had no idea what to name this thread. I know people have had the issue I’m having before. I read the forums that are on the issue. I’m getting a "“The name does no exist in current context error” but on a “MoseButtonDown” call. Not an a game object or asset. Every thread I saw hear had this error when referring to a game object in the code not…just code. I am so confused. Here is the snippet of code that is giving me trouble. Let me know if you need more.

void Update () {

     if (iFrame == 0) 

     {

          goHand.animation.Play("idle");
           iFrame++

     }

     else if (Input.GetButtonDown (OnMouseDown)) 

     {

          goHand.animation.Stop();
          iFrame++

     }

     v3DirectionRay = transform.TransformDirection(Vector3.forward); 

   }



It's part of a larger script. But in short what I'm  trying to do here is have a hand and fore arm model play an idle animation while holding an axe model. And then throw the axe when play clicks the mouse. Any ideas why Mono Develop won't accept the on Mouse Button down function? 

I actually have three errors at the moment:

  1. The name "On Mouse ButtonDown does not exist in current context.

  2. The best overloaded match for Unity engine input.get button.down string has invalid arguments.

  3. Argument #1 Cannot convert object expression to type “string”

Thanks for any insight into the matter. Looking forward to hear thoughts.

you can use

if (Input.GetMouseButton(0))
 {
//do something here
 }

you can refer to this “Unity - Scripting API: Input.GetMouseButton

Here is the syntax of function you are using

if (Input.GetButtonDown("some valid string"))
{       
       //do something here 
}

you must have not declare OnMouseDown as a string variable anywhere in your programme, so to make it working you can use

if (Input.GetButtonDown("Fire1"))
{       
       //do something here 
}

Hey! Thanks for the response! You know, I did look at the Unity API reference for OnMouseButtonDown. But I was confused what they meant by “Fire1.” I thought it was like, the name they were referencing as like a custom name for a key code or something? But that must be the actual KeyCode for Mouse left click eh? I thought it was literally mousegetbuttondown. Lol I’m still a little confused. But I’ll try editing my scripts and see what happens. But if you wouldn’t mind explaining this in more detail, that would be awesome. As I am learning C# and it takes me longer to get the concepts than most people I’m afraid. Thank you for your help!