- Home /
Question by
Wololo Plays · Jun 22, 2014 at 04:51 PM ·
playergameplaylifelifebar
Life Bar controlled
Hello, I have 2 script and a is I control a life bar. And the other is to calculate the fall .But I would not prescisase click to lower the life bar ,I would like to do this fall calculator do this for me.
Note: I'm Brazilian and my Unity is free And I'm kinda stupid in these parts so please let the script ready
#pragma strict
var Person : CharacterController;
var Velocidade : float;
var Pisando : boolean;
var Life : int;
var Dano : int = 2;
function Start () {
}
function Update () {
Person = GameObject.FindObjectOfType(CharacterController);
Velocidade = Person.velocity.magnitude;
}
function OnControllerColliderHit(Co : ControllerColliderHit){
if(Person.isGrounded){
Pisando = true;
}else{
Pisando = false;
}
if(Velocidade >= 14){
if(Pisando){
Life -=Velocidade * Dano;
}
}
}
-------------2º
#pragma strict
var texButton : GUISkin;
var posY: float;
var Alt: float;
var Lar: float;
var QntVida:float;
var MaxQntVida: float;
var tempo: float;
function Start () {
QntVida=100;
MaxQntVida=100;
}
function Update () {
Lar = Screen.width/4 * (QntVida/MaxQntVida);
posX = Screen.width/2 - Lar/2;
posY = Screen.height/2 - Screen.height/4;
Alt = Screen.height/10;
if (Input.GetKey("c"))
{
if (QntVida>0)
{
QntVida = QntVida-0.5;
tempo = -60;
}
}
if (tempo>=0)
{
if (QntVida<100)
{
if (tempo>0.01)
{
QntVida = QntVida+0.5;
tempo = 0;
}
}
}
tempo=tempo+Time.deltaTime;
}
function OnGUI()
{
GUI.skin = texButton;
GUI.Button(Rect(posX,posY,Lar,Alt)," ");
}
Comment
Answer by JusticeAShearing · Jul 05, 2014 at 04:08 PM
Well, here's a tutorial on stats bars, and another one on changing those stats. I hope that you find them useful. They are in English, however, but you can follow the video.
https://www.youtube.com/watch?v=tXYz4xe6p9c∈dex=20&list=PLB4DA4F8BDC3B82EE
https://www.youtube.com/watch?v=NNVP_9oWM4Q∈dex=49&list=PLB4DA4F8BDC3B82EE