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
1
Question by Yuu · May 12, 2011 at 02:09 PM · inputkeyboard

Keyboard Input Problem

Hi everyone !

I have a problem that I need help with. I want assign number 1,2,3 on the keyboard as hotkeys and whenever I press one of them, 3 objects 1,2,3 should have their materials changed accordingly to 3 sets of materials.

To make this easier to understand, for example when I press the "1" button on my keyboard, Object 1, Object 2 and Object 3 should have their materials changed to the material number 1 in their own material array. Below is my script to detect input and change the materials:

var materials_wall_left: Material[];

var materials_wall_right: Material[];

var materials_wall_top: Material[];

var getInput: String;

function Update()

{

 if(Input.anyKey)

 {

     ChangeWallMaterial();

 }


}

function ChangeWallMaterial()

{

 getInput = Input.inputString;

 var count:int;

 if(int.TryParse(getInput,count))

 {

     if(count > materials_wall_left.length)

         Debug.Log("Invalid choice");

     else if(Input.GetButtonUp(""+ getInput))

     {

         GameObject.Find("build_wall_left").renderer.material =

         materials_wall_left[count-1];

         GameObject.Find("build_wall_right").renderer.material =

         materials_wall_right[count-1];

         GameObject.Find("build_wall_top").renderer.material =

         materials_wall_top[count-1];

         Debug.Log(count);


     }

 }

}

Now my problem is that my keyboard doesn't seem to work with this. I tried 1,2,3 but nothing changed. When I tried pushing 4, the Log "Invalid choice" popped up.

The interesting thing is that when I try to run this from another computer via Team Viewer, I can change objects' materials just fine, no problems at all. After that, I came back to the first computer and tried using a virtual keyboard, and it works. So I wonder what's the problem with my physical keyboard, or the script itself ? Oh, and I tried plugging in 4-5 other keyboards, and tried this scene on 3 another computers. Yes, and I got the same result everytime. If you've encountered this problem before or know how to solve it, please tell me ! Thank you very much !

Note: my Unity version is 3.2 pro.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by keld-oelykke · Jun 06, 2011 at 08:38 PM

"else if(Input.GetButtonUp(""+ getInput))" is addressing logical buttons defined in the input manager ('Edit'->'Project Settings'->'Input')

... have you defined 1, 2 and 3 in there? or didn't you really mean to use the input manager functionality?

However, my guess is that it all works if you replace

"else if(Input.GetButtonUp(""+ getInput))"

with

"else if(0 < count)"

Hope it helps

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

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

2 People are following this question.

avatar image avatar image

Related Questions

How to distinguish between multiple keyboards? 1 Answer

How can i make button on iOS instead key 0 Answers

What just happened to my Unity!? 3 Answers

Checking whether string is a valid Input.Key 1 Answer

How can I combining two players to make one ? 1 Answer


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