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 Wylie · Oct 21, 2010 at 06:38 PM · button

How to script in a button press to continue?

How do I script it (in a two player game where both players alternate using the mouse for one click at a time) so that after the first player clicks, the second player can't click until he or she presses a button on the keyboard, and then after he clicks, the first player has to press another button on the keyboard.

How can I do this without resorting to loading separate levels each time a player clicks? I would prefer them to see the screen at all times.

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
Best Answer

Answer by jrfactotum · Oct 21, 2010 at 10:18 PM

I imagine you could do something similar to this (in a C# MonoBehaviour-derived class):

bool clicked = false; bool pressedButton = false;

void Update() { if (Input.GetMouseButtonUp(0)) clicked = true;

if (clicked && Input.GetKeyDown(GetPlayerButtonName())) pressedButton = true;

if (clicked && pressedButton) { clicked = false; pressedButton = false; SwitchPlayer(); } }

GetPlayerButtonName() would return the name of the keyboard button that the other player is required to press after the current player clicks.

Hope this helps.

Comment
Add comment · Show 4 · 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 Wylie · Oct 21, 2010 at 10:29 PM 0
Share

Okay, so I have some questions. First of all, I'm very new to scripting and I have been using JavaScript. I think I converted it fine, but how do I work with the GetPLayerButtonName() and SwitchPlayer(); I don't really understand where these come from and how I implement them into the script. Like do I define these things elsewhere, and what would I do to define them?

avatar image jrfactotum · Oct 22, 2010 at 01:18 AM 0
Share

Those are functions you'll have to write yourself. Sounds like you would benefit from an introduction to general Unity scripting:

http://unity3d.com/support/documentation/ScriptReference/index.html

http://unity3d.com/support/documentation/$$anonymous$$anual/Scripting.html

I'd hate to give you all the answers and deprive you of the benefit of figuring out how to implement simple functions, so I'll leave implementing those functions as an exercise for you.

avatar image jrfactotum · Oct 22, 2010 at 01:24 AM 0
Share

Actually, I will give you a hint about how to implement GetPlayerButtonName(). If the player is player 1 ('player' could be a member variable), return player 1's button name. If player 2, return player 2's button name. Input names for buttons, mice and other input devices are defined in Edit->Project Settings->Input. See here: http://unity3d.com/support/documentation/$$anonymous$$anual/Input.html

avatar image Wylie · Oct 22, 2010 at 02:13 PM 0
Share

Alright, thanks! Yeah, I just need a push in the right direction, I'll get on it.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

When my button is pressed the action reapeats 1 Answer

Array weapons Wheel scroll switch 1 Answer

How to make movement on camera on button down. 1 Answer

Making a Hover function for a button or toolbar from code. 2 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