Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 Snowhouse · Jun 12, 2021 at 08:22 PM · uimultiplayerbutton trigger events

all ui buttons applying to player 1, how do i make them apply to the player that clicked

i have some ui buttons and 1 - 4 players. the players can all move and attack and whatnot independently but if any player clicks a ui button it applies to player 1 always. in the editor during gameplay i can manually drag in a different player to the buttons target and then that player can use the buttons properly. obviously in a real game you cant access the editor so how do i detect which player clicked a button and then reassign the buttons target to be that player.

i.e.

ButtonScript // attached to canvas

{

public PlayerScript player; // attached in editor

public void DoButton(Gameobject Object )

{

player = player who clicked // this is the line/lines i cant figure out player.ReciveObject(object)

}

}

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
1

Answer by GetLitGames · Jun 13, 2021 at 12:24 PM

  1. Try to make sure that only one script handling local input is in the scene, usually this is the local player and you have some way in some code to determine if it is the local player or not and destroy the components on other replicated players in the scene.

  2. Know that local input is only coming from a local player.

Your question is only relevant if it's a couch game where multiple local player can give input, in this case maybe you have 4 copies of the input script and when the scripts are created in the scene you use the exact same script but have a property that is an integer that you set on each script to be 1,2,3,4 and in your code you check the number and read input from that controller. There will be some way in code to read input from different controllers. Add a Public Int PlayerNumber; to your script, then in the editor you can have 4 copies and set that integer to be 1,2,3,4. In your code you will either use a switch() or if() statement to check that integer and read from one of the controllers. If you aren't doing a local couch multiplayer game and it is a true online multiplayer game than what I mentioned in the beginning is true: Try to destroy any other copies and know that the input will always be from the local player. Remote players are irrelevant for input.

If you are doing couch multiplayer with the New Unity Input System, you can look at the Simple Multiplayer sample included in the Input System Package that shows how to setup local couch multiplayer: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Components.html#playerinputmanager-component

You can also try this video, which shows adding the Player Inputs and PlayerInputManager - but you should review the documentation and see if the official Simple Multiplayer sample does what you need first: https://www.youtube.com/watch?v=iFrO4bqmOPU

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 Snowhouse · Jun 14, 2021 at 09:07 PM 0
Share

hey thanks this helped, i got it to work messily, I set up an array in the button script and got it so the player sends its player number to the button script. the only thing stopping it working cleanly is ,using the new input system, i cant figure out how to do a Get button up on a script meant for a ui element. i can do for the actual player but when i add a player input component to a ui element, that element stops showing up on the canvas

avatar image GetLitGames Snowhouse · Jun 15, 2021 at 01:37 PM 0
Share

OK now that I know what you are using, I added details about what to use. You should look at the Simple Multiplayer sample and see if you can modify the prefabs or code from that to do what you need since it's an official example.

avatar image
0

Answer by Snowhouse · Jun 13, 2021 at 08:12 PM

thank you, ill try to apply this. it is for a couch coop game using the new input system and each player does have an index number.

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

281 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 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 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 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 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 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 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 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 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 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 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 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

Multiplayer Canvas not showing on client? 1 Answer

Buttons don't trigger only in build 0 Answers

2 players 1 game field in shooter/card game 0 Answers

How to Synchronize Buttons in a lobby? 0 Answers

im making a multiplayer game, and it has buttons that allow you to craft different blocks, how do I set a reference to the player game object so each player can build different amounts of blocks? 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