Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by dhotlo2 · Nov 02, 2016 at 05:59 PM · multiplayermobileevent triggering

Event Triggers to move player not working in multiplayer on mobile device.

Basically everything worked fine on my cube player before I started trying to get a multiplayer demo going. I got multiplayer connecting and I can see the other cube player moving around. Except, my touch buttons on my screen no longer work on the mobile device. I poked around and it is because I have Event Triggers set to functions that move the cube around. If I pause unity and manually add the Player(clone) and do the Event triggers that way, the cube can be moved again. If I attach the Canvas with the UI buttons to the player, then when the player spawns, the controls work again, but they rotate with the player as it moves. I have tried a script to detach the child after spawning, and that works also, problem now is that when another player joins the game, their canvas spawns and detaches also, so there are 2 canvases overlapping each other on both screens, making one of them unreachable. I have tried to instantiate the canvas with the UI buttons after your player spawns, and while it does instantiate the canvas correctly, the buttons again do not work. This is driving me crazy! What is the proper process here?

Comment
Add comment · Show 2
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 dhotlo2 · Nov 02, 2016 at 10:02 PM 0
Share

@magnomous @mateo4632 You two had similar questions but I don't know how to contact a user on unity. Wondering if you could help with some input.

avatar image Magnomous dhotlo2 · Nov 03, 2016 at 08:59 AM 0
Share

You just need to assign events of the Event Trigger via code. They won't be visible in the inspector, but they are in there. This is a part of the code from the game I coded. It's triggered once you tap the screen and calls the function to move your character:

             EventTrigger.Entry entry1 = new EventTrigger.Entry();
             entry1.eventID = EventTriggerType.Drag;
             entry1.callback.AddListener((eventData) => { GetComponent<Player$$anonymous$$ovement>().OnJoystickDrag(); });
             joystickDragArea.GetComponent<EventTrigger>().triggers[2] = entry1;


1 Reply

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

Answer by dhotlo2 · Nov 03, 2016 at 01:32 PM

@Magnomous So I have to assign events with code instead of doing it in the inspector, but I am having a bit of a problem understanding the code fully. For my game, there is a left and right button that adds a force to a cub to make it move. On the Right button for example, there is an event trigger to call the RightClick() function which applies a force on pointerdown. Do I put this code on the player movement script then? Could you add some comments to each line maybe? I have buttons so I'm assuming I don't need to have OnJoystickDrag(); in there but something else?

Comment
Add comment · Show 16 · 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 Magnomous · Nov 03, 2016 at 01:45 PM 0
Share

It really depends on what kind of game you have. Assigning events in code is viable pretty much only when they need to be assigned during runtime. Do you instantiate this cube at runtime or is it already in the scene? $$anonymous$$aybe all you need to do is something like this:

 rightButton.GetComponent<Button>().onClick.AddListener(() => { go.GetComponent<PlayerController>().RightClick(); });

"rightButton" would be a gamobject containing a Button component. "go" would be a gameobject with your script that contains RightClick funciton - in my example the script would be called PlayerController.

avatar image dhotlo2 Magnomous · Nov 03, 2016 at 02:07 PM 0
Share

The cube player gets spawned when the game starts, it is a multiplayer game, so when you join a session, your player gets instantiated.

avatar image dhotlo2 dhotlo2 · Nov 03, 2016 at 02:29 PM 0
Share

@$$anonymous$$agnomous I see. I don't understand why the code is all red still and not recognized?

Show more comments
avatar image dhotlo2 Magnomous · Nov 03, 2016 at 07:39 PM 0
Share

@$$anonymous$$agnomous ok so one more quick question and I will leave you alone since you made a multiplayer mobile game. What should the optimal settings be in the Inspector on the player for Network Transform (script)? As in the movement threshold , snap threshold, interpolate movement. I looked up a few of them and I understand what some are, but others are very confusing. What should the settings be for I guess Optimal syncing of the Player Cubes (They are rigidbodies and move with AddForce).

avatar image Magnomous dhotlo2 · Nov 03, 2016 at 07:47 PM 0
Share

Well, I used Photon networking and since you are using Network Transform, I suppose you use the standard unity networking, which I don't have experiences with. But generally you need to guess what optimal settings should be and test whether they suit you. I think you should also check some youtube tutorials about unity networking. They would probably give you a good understanding what exactly these settings do.

avatar image dhotlo2 · Nov 03, 2016 at 01:56 PM 0
Share

I guess to elaborate more on my Specific Example: I have a canvas with the UI Buttons on screen. Then I have a player prefab that has the playermovement script on it. In the Playermovement script I have functions to move the player with force that use bools to trigger the movement on and off, based on whether a button is touched or not. So for example the right button movement looks like: public void RightClick(){ isRightClicked = true; } and then in the Update function I have :

void Update(){ If (isRightClicked) { rb.addforce(5,0,0); } }

Where would I input the event trigger code in my example? Can I assign the event triggers in the Start() function , so that they get assigned for each player as they spawn?

avatar image Magnomous dhotlo2 · Nov 03, 2016 at 02:08 PM 1
Share

Is it a networked, multiplayer game? If so, then yes, I think you can assign it in the Start(), but you should also include something like if(photonView.is$$anonymous$$ine), then assign this button to $$anonymous$$e, and only $$anonymous$$e cube (you don't want to make an input to the cubes that you should not be able to control, do you?)- that would be for Photon networking. And the onClick assignment could look like:

 rightButton.GetComponent<Button>().onClick.AddListener(() => { go.GetComponent<Playermovement>().RightClick(); });

and the "go" would be a GameObject - your cube. RightButton would be a child object of the Canvas - the rightbutton GameObject.

avatar image dhotlo2 Magnomous · Nov 03, 2016 at 02:17 PM 0
Share

It's all red when i put that in the Start function. Also I am using Pointer Down ins$$anonymous$$d of onClick , and I was reading that your line of code only works for onClick?

Show more comments

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

118 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

Related Questions

Multiple mobile devices 0 Answers

i need help with my scipt ( photon mobile)!!!!! 0 Answers

Best way to set up mobile multiplayer 0 Answers

OnPointerDown for iOS delayed? 1 Answer

Login register in android (MAMP) 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