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 mdttheory · Nov 09, 2014 at 06:00 PM · gui-textplayer-health

Attach GUI element to newly spawned player as their GUI

Goal: Design and implement a multiplayer GUI. Specifically a hitpoints readout while also keeping the readout separate from other players in the same server.

I came across a few tutorials of the new 4.6 UI features and the typical method of adjusting the value of a slider or text is to:

1) Attach a script to an object

2) Write the GUI controls into the script (update hitpoints -> change slider value, for example)

3) Drag the GUI element from the hierarchy to the script in the inspector

The problem is the players with the health scripts attached are not spawned until they join a game. This means I would have to attach the slider to the script after the player spawns else I get object reference issues.

Suggestions? I am open to a better method as well. Thank you!

Comment
Add comment · Show 1
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 tata_unlimited · Sep 21, 2015 at 09:52 AM 0
Share

Hi. Same problem here with UI in unity 5.1. Did you find any way to solve it?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by barjed · Nov 09, 2014 at 06:49 PM

Prepare a Prefab with all the connections and references inside. Leave an empty public property for the player object to connect in.

When a player spawns, simply instantiate the prefab using Instantiate(), fill in the missing property and you're good to go :)

Comment
Add comment · Show 1 · 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 mdttheory · Nov 09, 2014 at 07:34 PM 0
Share

Thank you for your response!

To clarify:

I have a player prefab. If I leave the prefab in the project browser, select it, and try to drag my slider UI element to the inspector window onto the player's "health" script (it as a slot for it because the script has public Slider slider;) it won't let me drop it there.

Alternatively, if I first drop the prefab into the world and then follow the steps above I -can- attach the UI element to the player's health script in the inspector. However, when I save this player as my new prefab the UI element is detached.

I do instantiate the prefab when the player spawns. GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);

fill in the missing property and you're good to go :)

This is basically what I am asking how to do. How do I do this? :)

Ultimately all I want to do is have the player's health reflected in the UI element. Either a slider or text will do as I'm sure the method is similar.

Thanks again!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Inheritance (Printing a toString for subclasses) 3 Answers

How do you keep text inside miniCams 0 Answers

Update Gui Text with Score 2 Answers

GUI text Messages does not show and points counter do not stop at its prefixed limit 2 Answers

Display controls in-line with text? 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