• 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 StigDesign · Dec 25, 2014 at 11:13 PM · score

How to get Score to React in C# PROJECT: SURVIVAL SHOOTER Tutorial

Hello i know it silly but i try to expand on teh PROJECT: SURVIVAL SHOOTER tutorial i have added barrels that reacts if shot on i ended up on using same scpirt as enemy Health. now i try to make a chest that reacts when in trigger(box collider set as trigger) some how it all works except adding score value to the hud i thinked maby enemy health had special referenc to the score manager at start of script but i only see the newscore float and the adding at bottom of the script her is my code i try using UnityEngine; using System.Collections;

 public class PickUp_Score : MonoBehaviour
 {
 
     // The Value for the LOOT!!!!
     public int Money = 10;
     // Sound to play when colides/ gets the Reward
     public AudioClip reward;
 
 
     // action when enter the trigger colider
     void OnTriggerEnter(Collider Player)
     {
         audio.PlayOneShot (reward, 0.1f);
         ScoreManager.score += Money;
         // Debug.Log ("Score Egentlig");
         Destroy (gameObject, 0.1f);
     }
 
 }

Enemy Health is this one using UnityEngine;

 namespace CompleteProject
 {
     public class EnemyHealth : MonoBehaviour
     {
         public int startingHealth = 100;            // The amount of health the enemy starts the game with.
         public int currentHealth;                   // The current health the enemy has.
         public float sinkSpeed = 2.5f;              // The speed at which the enemy sinks through the floor when dead.
         public int scoreValue = 10;                 // The amount added to the player's score when the enemy dies.
         public AudioClip deathClip;                 // The sound to play when the enemy dies.
 
 
         Animator anim;                              // Reference to the animator.
         AudioSource enemyAudio;                     // Reference to the audio source.
         ParticleSystem hitParticles;                // Reference to the particle system that plays when the enemy is damaged.
         CapsuleCollider capsuleCollider;            // Reference to the capsule collider.
         bool isDead;                                // Whether the enemy is dead.
         bool isSinking;                             // Whether the enemy has started sinking through the floor.
 
 
         void Awake ()
         {
             // Setting up the references.
             anim = GetComponent <Animator> ();
             enemyAudio = GetComponent <AudioSource> ();
             hitParticles = GetComponentInChildren <ParticleSystem> ();
             capsuleCollider = GetComponent <CapsuleCollider> ();
 
             // Setting the current health when the enemy first spawns.
             currentHealth = startingHealth;
         }
 
 
         void Update ()
         {
             // If the enemy should be sinking...
             if(isSinking)
             {
                 // ... move the enemy down by the sinkSpeed per second.
                 transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);
             }
         }
 
 
         public void TakeDamage (int amount, Vector3 hitPoint)
         {
             // If the enemy is dead...
             if(isDead)
                 // ... no need to take damage so exit the function.
                 return;
 
             // Play the hurt sound effect.
             enemyAudio.Play ();
 
             // Reduce the current health by the amount of damage sustained.
             currentHealth -= amount;
             
             // Set the position of the particle system to where the hit was sustained.
             hitParticles.transform.position = hitPoint;
 
             // And play the particles.
             hitParticles.Play();
 
             // If the current health is less than or equal to zero...
             if(currentHealth <= 0)
             {
                 // ... the enemy is dead.
                 Death ();
             }
         }
 
 
         void Death ()
         {
             // The enemy is dead.
             isDead = true;
 
             // Turn the collider into a trigger so shots can pass through it.
             capsuleCollider.isTrigger = true;
 
             // Tell the animator that the enemy is dead.
             anim.SetTrigger ("Dead");
 
             // Change the audio clip of the audio source to the death clip and play it (this will stop the hurt clip playing).
             enemyAudio.clip = deathClip;
             enemyAudio.Play ();
         }
 
 
         public void StartSinking ()
         {
             // Find and disable the Nav Mesh Agent.
             GetComponent <NavMeshAgent> ().enabled = false;
 
             // Find the rigidbody component and make it kinematic (since we use Translate to sink the enemy).
             GetComponent <Rigidbody> ().isKinematic = true;
 
             // The enemy should no sink.
             isSinking = true;
 
             // Increase the score by the enemy's score value.
             ScoreManager.score += scoreValue;
 
             // After 2 seconds destory the enemy.
             Destroy (gameObject, 2f);
         }
     }
 }

and Score Manager is this using UnityEngine; using UnityEngine.UI; using System.Collections;

 namespace CompleteProject
 {
     public class ScoreManager : MonoBehaviour
     {
         public static int score;        // The player's score.
 
 
         Text text;                      // Reference to the Text component.
 
 
         void Awake ()
         {
             // Set up the reference.
             text = GetComponent <Text> ();
 
             // Reset the score.
             score = 0;
         }
 
 
         void Update ()
         {
             // Set the displayed text to be the word "Score" followed by the score value.
             text.text = "Score: " + score;
         }
     }
 }

so if you that read this got a clue Please help :) ps Norwegian with Dyselexia and not used to forum or enny.

while this waits for aproval by mod i have tried enumerator or what its called to get it whait for 2 seconds in case it had to do with it deletes to fast or some thing but stil didnt helped. i tried to make a js variant fo it byt got more troubels XD

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Timer Score display on Game Over Scene? 1 Answer

i cant figure this out i have 2 scripts and a static variable i need the variable to add 1 everytime the enemy hits me. 1 Answer

How to center the score in screen? 1 Answer

Accessing Script From Other Script Causes Lag? 1 Answer

distance based score system 3 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