- Home /
[ASK] adding Lives System to 2.5D side scroller
halo, im new in unity.
i want to ask about lives system fo 2.5D,
so i want to add lives ( not health ) to my character, so when the lives run out, then game is over.
i need help for modify this script,
here the script,
player health
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class playerHealth : MonoBehaviour { public float fullHealth; float currenthealth;
public GameObject playerDeathFX;
public Slider playerHealthSlider;
public Image damageScreen;
Color flashColor = new Color (255f,255f,255f,1f);
float flashSpeed = 5f;
bool damaged = false;
AudioSource PlayerAS;
// Use this for initialization
void Start () {
currenthealth = fullHealth;
playerHealthSlider.maxValue = fullHealth;
playerHealthSlider.value = currenthealth;
PlayerAS = GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update () {
if (damaged) {
damageScreen.color = flashColor;
} else {
damageScreen.color = Color.Lerp (damageScreen.color, Color.clear, flashSpeed * Time.deltaTime);
}
damaged = false;
}
public void addDamage(float Damage) {
currenthealth -= Damage;
playerHealthSlider.value = currenthealth;
damaged = true;
PlayerAS.Play ();
if(currenthealth <= 0 ) {
makeDead ();
}
} public void addHealth (float health) { currenthealth += health; if (currenthealth > fullHealth) currenthealth = fullHealth; playerHealthSlider.value = currenthealth; } public void makeDead(){ Instantiate(playerDeathFX, transform.position, Quaternion.Euler(new Vector3(-90,0,0))); Destroy(gameObject); } }
And here is Player Controller
using UnityEngine; using System.Collections;
public class PlayerControler : MonoBehaviour { public float runspeed; public float walkspeed; bool running;
Rigidbody RB;
Animator Anim;
bool facingright;
//jump
bool grounded = false;
Collider[] groundCollisions;
float groundCheckRadius = 0.2f;
public LayerMask groundLayer;
public Transform groundCheck;
public float jumpHeight;
// Use this for initialization
void Start () {
RB = GetComponent<Rigidbody> ();
Anim= GetComponent<Animator> ();
facingright = true;
}
// Update is called once per frame
void Update () {
}
void FixedUpdate() {
running = false;
if (grounded && Input.GetAxis ("Jump") > 0) {
grounded = false;
Anim.SetBool ("grounded", grounded);
RB.AddForce (new Vector3 (0, jumpHeight, 0));
}
groundCollisions = Physics.OverlapSphere (groundCheck.position, groundCheckRadius, groundLayer);
if (groundCollisions.Length > 0) grounded = true;
else
grounded = false;
Anim.SetBool ("grounded", grounded);
float move = Input.GetAxis("Horizontal");
Anim.SetFloat ("speed",Mathf.Abs(move));
float sneaking = Input.GetAxisRaw ("Fire3");
Anim.SetFloat ("sneaking",Mathf.Abs(sneaking));
float firing = Input.GetAxis ("Fire2");
Anim.SetFloat ("shooting", firing);
if (sneaking > 0 || firing >0 && grounded ) {
RB.velocity = new Vector3 (move * walkspeed, RB.velocity.y, 0);
}
else {
RB.velocity = new Vector3 (move * runspeed, RB.velocity.y, 0);
if (Mathf.Abs(move) >0) running = true;
}
if (move>0 && !facingright) Flip ();
else if (move<0 && facingright) Flip ();
}
void Flip(){
facingraight = !facingright;
Vector3 theScale = transform.localScale;
theScale.z *= -1;
transform.localScale = theScale;
}
public float GetFacing ()
{
if (facingright)
return 1;
else
return -1;
}
public bool getRunning(){
return (running);
}
}
please help
thank you so much
Your answer
Follow this Question
Related Questions
Grappling Hook in 2.5d Game 0 Answers
2D - locking the z axis using CharacterController.move 1 Answer
How do I do movement in a Beat Em Up? (2D movement w/ jumping in a pseudo-3D environment) 2 Answers
How to edit Direction Angle using GetAxis 2.5D 8 direction movement 1 Answer
Blurry sprite on material 0 Answers