Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 SlowSpeed · Jul 27, 2015 at 10:38 AM · scenestatictemplate

How can I create static floating information?

Hi I would like to create a static floating information, like score, hp, etc.

It needs to be at the same place even if the camera is moving and to be the same on every level, even if changed, I want it to change on all the levels together so I won't have to go over all the levels and redefine it.

kinda like a static frame of information.

Thanks :)

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 PAHeartBeat · Jul 27, 2015 at 10:42 AM

Hi @SlowSpeed

If I am not wrong then you are talking about a animation will play in camera sapce, it's dosnt matter what is the camear location. If YES, then it is very simple, just place animation object as child of camera, set position as per your aspect of view and then play your static animation.

Once you set your animation object as child of camera, it will also move with camera if move or rotated.

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 SlowSpeed · Jul 27, 2015 at 04:59 PM 0
Share

Thanks for your replay I do need something like what you said but I would like to know whether it's possible to set this only once and to be applied to all levels without me having to copy it to every level.

avatar image rocket350 · Jul 27, 2015 at 05:26 PM 1
Share

If combine the two answers (even though one has nothing to do with the question), you could create a camera with the child object in the first Scene of your game with and put this script on it:

 using UnityEngine;
 using System.Collections;
 
 public class CameraScript : $$anonymous$$onoBehaviour {
     void Awake(){
         if(FindObjectOfType<CameraScript>()!=null)
             DestroyImmediate (gameObject);
         DontDestroyOnLoad (gameObject);
     }
 
 }


You also need to attach this script to the cameras in the other scenes or completely delete them (the cameras).

avatar image
1

Answer by Hexer · Jul 27, 2015 at 05:06 PM

static floating information. these are static public variables that can be accesed from another script. To access them from another script. you have to reference them as "ScriptName.hp" instead of hp in the other script.

   //script 1 with the variables.
  public class PlayerManager : MonoBehaviour {
     static public float hp;
     static public float score;
 
 
   //script2 - how to refer hp in another script
     PlayerManager.hp

While you go through the levels you want to safe the data. When the scene starts you want to call PlayerPrefs.GetFloat and when the scene ends you want to call PlayerPrefs.SetFloat. http://docs.unity3d.com/ScriptReference/PlayerPrefs.html

It might also be worth to check DontDestroyOnLoad. Although I don't know if this would work on variables inside a script. http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

The ideal idea would be to use a combination of both. Have a gameObject with the script that Gets and Set the PlayerPrefs and when loading another scene, dont destroy this gameObject so that you can carry this gameObject to multiple scenes without constantly re adding it to the scene

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 rocket350 · Jul 27, 2015 at 05:17 PM 0
Share

Though a great answer, I don't think SlowSpeed meant that by his question. :/

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

Combined Mesh (root: scene) - How can I detect if a Mesh is a static combination? 1 Answer

I´ve got a problem with my Coin System. It always shows 1 Coin. 2 Answers

Death Counter Resets When Reloading Scene. 3 Answers

How to access variables from other scripts without static (javascript) 1 Answer

How do i imports my variable to another variable and save it with PlayerPrefs? 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