- Home /
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.
Answer by stblue · Sep 17, 2014 at 01:38 PM
you can use
if (Input.GetMouseButton(0))
{
//do something here
}
you can refer to this "http://docs.unity3d.com/ScriptReference/Input.GetMouseButton.html"
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
}
Answer by C10110 · Sep 17, 2014 at 04:45 PM
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!
ok so there are predefined axes array in unity you can look at them by going to Edit->project settings->Input in your inspector you have axes array, there you can find "Fire1" with value you can expand that and look that button assign for fire1 is mouse0, you can change those value according to your need.so if you are comfortable with these than its ok or else you can always use Input.Get$$anonymous$$ouseButton(0) for left click.
Alright sounds good. Thank you very much for your help. I was able to get the code to compile right away and understand what's going on now.
Your answer
Follow this Question
Related Questions
Array - Convert Object into Int 5 Answers
iOS Not Converting String to Integer 0 Answers
Get JSON array object string value 2 Answers
Generate Terrain 2 Answers
How would you put a texture on a cube using c#? (SOLVED) 0 Answers