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 mateo4632 · Feb 08, 2016 at 05:30 AM · movementinstantiateprefabsbuttonsevent triggering

EventTrigger on button not recognizing instantsiated player

So I'm working on a multiplayer game for mobile devices and I have these buttons with event triggers on them so when I click them they move the player forward and so on. Now I have it so OnPress the buttons turn a boolean true and when it is true the player ship moves according to which buttons is pressed. But since the Canvas and buttons that make the player move have no scripts attached, the event trigger has to get the inputs from the player. Now the problem is that the event triggers needed a gameobject to know what to do for when each button is pressed. So i dragged the prefab player spaceship into there and set it up so it should work. The only problem is when the player gets instantsiated over the network, the buttons no longer work since it is trying to access the prefab that has everything deactivated, unless it is your photon view. (I am using Photon Networking) So if i manually turn the booleans true the ship does move, but the buttons don't work.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class PlayerMovementTouch : MonoBehaviour, IEventSystemHandler
 {
     public float Speed = 15;
     public float RotSpeed = 180;
     
     private Rigidbody2D playerRigidbody;
     private TouchMovement touchMovement;
     public bool buttonHeldUp = false;
     public bool buttonHeldDown = false;
     
 
     void Start()
     {
         if (!this.gameObject.GetComponent<PlayerNetworkMover> ().IsMyView) 
         {
             GameObject.Find("CanvasButton").SetActive(false);
         }
         playerRigidbody = GetComponent<Rigidbody2D>();
     }
 
     public void pressedUp (BaseEventData eventData)
     {
         buttonHeldUp = true;
     }
     public void notpressedUp (BaseEventData eventData)
     {
         buttonHeldUp = false;
     }
 
     public void pressedDown (BaseEventData eventData)
     {
         buttonHeldDown = true;
     }
     public void notpressedDown(BaseEventData eventData)
     {
         buttonHeldDown = false;
     }
     
     public void Update()
     {
         if (buttonHeldUp == true)
         {
             // Do stuff
             Debug.Log ("clickUp");
             // Move Character
             playerRigidbody.AddForce(transform.up * Speed);
         } 
         else
             Debug.Log ("not click Up");
 
         if (buttonHeldDown == true)
         {
             // Do stuff
             Debug.Log ("clickDown");
             // Move Character
             playerRigidbody.AddForce(transform.up * -Speed);
         } 
         else
             Debug.Log ("not click Down");
     }
 }

Any help is would be great!

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 dhotlo2 · Nov 02, 2016 at 09:02 PM

I have had this same exact issue for 2 days now, have you found a solution to it?

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

49 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

Related Questions

Destroy a prefab from another class 2 Answers

problems with instantiating a moving prefab. 0 Answers

Difficulty parameter not correctly affecting spawn rate on button click 1 Answer

Instantiate more than 1 prefab 0 Answers

How to move an Instantiated Object towards a moving Object? 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