Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Amart · Oct 02, 2016 at 05:37 AM · 2.5dlives

[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

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

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


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