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 /
  • Help Room /
This question was closed Mar 09, 2020 at 11:17 AM by tormentoarmagedoom for the following reason:

Too subjective and argumentative

avatar image
0
Question by dipeshjethwa63 · Mar 09, 2020 at 07:22 AM · updatescorebarhealth

how to update score and health throughout different scenes.

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.SceneManagement;
     
     public class PlayerHealth : MonoBehaviour
     {
         public static PlayerHealth Instance;
         public  int health;
         public GameObject deathEffect;
     void Awake()
         {
             if (Instance == null)
             {
                 DontDestroyOnLoad(gameObject);
                 Instance = this;
             }
             else if (Instance != this)
             {
                 Destroy(gameObject);
             }
             FindObjectOfType(typeof(Transform));
         }
         public void TakeDamage(int damage)
         {
             health -= damage;
     
             StartCoroutine(DamageAnimation());
     
             if (health <= 0)
             {
                 Die();
                
             }
         }
     
         void Die()
         {
             SceneManager.LoadScene("Game Over");
         }
         public void Damage(int dmg)
         {
             health -= dmg;
         }
     
         IEnumerator DamageAnimation()
         {
             SpriteRenderer[] srs = GetComponentsInChildren<SpriteRenderer>();
     
             for (int i = 0; i < 3; i++)
             {
                 foreach (SpriteRenderer sr in srs)
                 {
                     Color c = sr.color;
                     c.a = 0;
                     sr.color = c;
                 }
     
                 yield return new WaitForSeconds(.1f);
     
                 foreach (SpriteRenderer sr in srs)
                 {
                     Color c = sr.color;
                     c.a = 1;
                     sr.color = c;
                 }
     
                 yield return new WaitForSeconds(.1f);
             }
         }
        
     }    
     
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Enemyflip : MonoBehaviour
 {
    
     public Transform player;
 
     public bool isFlipped = false;
  
     public void LookAtPlayer()
     {
         Vector3 flipped = transform.localScale;
         flipped.z *= -1f;
 
         if (transform.position.x > player.position.x && isFlipped)
         {
             transform.localScale = flipped;
             transform.Rotate(0f, 180f, 0f);
             isFlipped = false;
            
         }
         else if (transform.position.x < player.position.x && !isFlipped)
         {
             transform.localScale = flipped;
             transform.Rotate(0f, 180f, 0f);
             isFlipped = true;
         }
         
     }
     }
 
     using System;
     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.UI;
     
     public class HealthBar : MonoBehaviour
     {
         
         public PlayerHealth playerHealth;
         public Slider slider;
         
         void Start()
         { 
             slider.maxValue = playerHealth.health;
             DontDestroyOnLoad(gameObject);
         }
     
         // Update is called once per frame
         void Update()
         {
             slider.value = playerHealth.health;   
         }
     
         internal void SetmaxHealth(int maxHealth)
         {
             throw new NotImplementedException();
         }
     
         internal void SetHealth(int maxHealth)
         {
             throw new NotImplementedException();
         }
       
     }
     
     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.UI;
     public class ScoreController : MonoBehaviour
     {
         //static ScoreController Instance;
         public  Text scoreText ;
         private  int score;
     void Start()
         {
             score = 0;
             UpdateScore();
     }
     public void AddScore(int newScorevalue)
         { 
             score += newScorevalue;
             UpdateScore();  
         }
         // Update is called once per frame
         void UpdateScore()
         {
             scoreText.text= "Score:" + score;
         }
         }
     
         public class ScoreController : MonoBehaviour
         {
          public  Text scoreText ;
             private  int score;
         void Start()
             {
                 score = 0;
                 UpdateScore();
           }
         public void AddScore(int newScorevalue)
             { 
                 score += newScorevalue;
                 UpdateScore();  
             }
             // Update is called once per frame
             void UpdateScore()
             {
                 scoreText.text= "Score:" + score;
             }
         }



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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by tormentoarmagedoom · Mar 09, 2020 at 11:17 AM

Hello.

First, this is not a script service provider..

Do not post your code and wait for people to give youthe code.

Second, go learn about data persistance between scenes.

Post closed.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

204 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i Reset Health,Score,Time??? 0 Answers

Score, FixedUpdate and Update 0 Answers

Score wont display 0 Answers

My health bars image.fillAmount doesnt change. 4 Answers

Opening Project Error 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