Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by C10110 · Sep 17, 2014 at 01:23 PM · objectstringconvertinvalidcannot

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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 
 }





Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image stblue · Sep 17, 2014 at 06:01 PM 0
Share

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.

avatar image C10110 · Sep 17, 2014 at 06:57 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges