- Home /
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 :)
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.
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.
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).
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
Though a great answer, I don't think SlowSpeed meant that by his question. :/
Your answer
Follow this Question
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