• 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 NunoMSSilva19 · May 28, 2020 at 05:34 PM · scripting problemfps1st person

Kill, Double Kill, Triple Kill! How I put this in the game?

Hi people, I made a script to put a kill, Double Kill, Triple Kill (voice) in the game. However Doesn´t work... Someone can help me, writing a right script for me! Below is the script I made. Thanks!

 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 
 [RequireComponent(typeof(PlayerSetup))]
 public class Player : NetworkBehaviour {
 
     [SyncVar]
     private bool _isDead = false;
     public bool isDead
     {
         get { return _isDead; }
         protected set { _isDead = value; }
     }
 
     [SerializeField]
     private int maxHealth = 100;
 
     [SyncVar]
     private int currentHealth;
 
     public float GetHealthPct ()
     {
         return (float)currentHealth / maxHealth;
     }
 
     [SyncVar]
     public string username = "Loading...";
 
     public int kills;
     public int deaths;
 
     [SerializeField]
     private Behaviour[] disableOnDeath;
     private bool[] wasEnabled;
 
     [SerializeField]
     private GameObject[] disableGameObjectsOnDeath;
 
     [SerializeField]
     private GameObject deathEffect;
 
     [SerializeField]
     private GameObject spawnEffect;
 
     private bool firstSetup = true;
 
 
     public AudioSource audioPlayer;
     public AudioClip[] killStreakSounds;
     int currentStreak = 0;
     float killTimer = 0;
     const float streakReset = 1;
 
     public void SetupPlayer ()
     {
         if (isLocalPlayer)
         {
             //Switch cameras
             GameManager.instance.SetSceneCameraActive(false);
             GetComponent<PlayerSetup>().playerUIInstance.SetActive(true);
         }
 
         CmdBroadCastNewPlayerSetup();
     }
 
     [Command]
     private void CmdBroadCastNewPlayerSetup ()
     {
         RpcSetupPlayerOnAllClients();
     }
 
     [ClientRpc]
     private void RpcSetupPlayerOnAllClients ()
     {
         if (firstSetup)
         {
             wasEnabled = new bool[disableOnDeath.Length];
             for (int i = 0; i < wasEnabled.Length; i++)
             {
                 wasEnabled[i] = disableOnDeath[i].enabled;
             }
 
             firstSetup = false;
         }
 
         SetDefaults();
     }
 
     //void Update()
     //{
     //   if(KillTimer > 0)
     //   {
     //      KillTimer -= Time.deltaTime;
     //      if(KillTimer <= 0) ResetStreak();
     //   }
 
     //    if (!isLocalPlayer)
     //        return;
 
     //    if (Input.GetKeyDown(KeyCode.K))
     //    {
     //        RpcTakeDamage(99999);
     //    }
     //}
 
 [ClientRpc]
     public void RpcTakeDamage (int _amount, string _sourceID)
     {
         if (isDead)
             return;
 
         currentHealth -= _amount;
 
         Debug.Log(transform.name + " now has " + currentHealth + " health.");
 
         if (currentHealth <= 0)
         {
             Die(_sourceID);
         }
     }
 
     private void Die(string _sourceID)
     {
         
     isDead = true;
 
         Player sourcePlayer = GameManager.GetPlayer(_sourceID);
         if (sourcePlayer != null)
         {
             sourcePlayer.kills++;
             GameManager.instance.onPlayerKilledCallback.Invoke(username, sourcePlayer.username);
         }
 
         deaths++;
 
         //Disable components
         for (int i = 0; i < disableOnDeath.Length; i++)
         {
             disableOnDeath[i].enabled = false;
         }
 
         //Disable GameObjects
         for (int i = 0; i < disableGameObjectsOnDeath.Length; i++)
         {
             disableGameObjectsOnDeath[i].SetActive(false);
         }
 
         //Disable the collider
         Collider _col = GetComponent<Collider>();
         if (_col != null)
             _col.enabled = false;
 
         //Spawn a death effect
         GameObject _gfxIns = (GameObject)Instantiate(deathEffect, transform.position, Quaternion.identity);
         Destroy(_gfxIns, 3f);
 
         //Switch cameras
         if (isLocalPlayer)
         {
             GameManager.instance.SetSceneCameraActive(true);
             GetComponent<PlayerSetup>().playerUIInstance.SetActive(false);
         }
 
         Debug.Log(transform.name + " is DEAD!");
 
         StartCoroutine(Respawn());
     }
 
     private IEnumerator Respawn ()
     {
         yield return new WaitForSeconds(GameManager.instance.matchSettings.respawnTime);
 
         Transform _spawnPoint = NetworkManager.singleton.GetStartPosition();
         transform.position = _spawnPoint.position;
         transform.rotation = _spawnPoint.rotation;
 
         yield return new WaitForSeconds(0.1f);
 
         SetupPlayer();
 
         Debug.Log(transform.name + " respawned.");
     }
 
     public void SetDefaults ()
     {
         isDead = false;
 
         currentHealth = maxHealth;
 
         //Enable the components
         for (int i = 0; i < disableOnDeath.Length; i++)
         {
             disableOnDeath[i].enabled = wasEnabled[i];
         }
 
         //Enable the gameobjects
         for (int i = 0; i < disableGameObjectsOnDeath.Length; i++)
         {
             disableGameObjectsOnDeath[i].SetActive(true);
         }
 
         //Enable the collider
         Collider _col = GetComponent<Collider>();
         if (_col != null)
             _col.enabled = true;
 
         //Create spawn effect
         GameObject _gfxIns = (GameObject)Instantiate(spawnEffect, transform.position, Quaternion.identity);
         Destroy(_gfxIns, 3f);
     }
 
     private void Die()
     {
        audioPlayer.PlayOneShot(killStreakSounds[currentStreak]);
        if (currentStreak < killStreakSounds.Length - 1) currentStreak++;
        killTimer = streakReset;
     }
 
     void ResetStreak() // Call this when your character dies
     {
        currentStreak = 0;
        killTimer = 0;
     }
 
        
 
 }
 




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

· Add your reply
  • Sort: 
avatar image
0

Answer by Map-Builder · May 28, 2020 at 11:57 PM

HI, hey that's not working, can you help me ?



Huge code incoming


:/


Sorry but...

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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

270 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 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

Why do all the bullets come out at once? 1 Answer

Need help with FPS Shooting AI Behaviour script 2 Answers

Problem with gun/shooting scripting 0 Answers

Aim down Sights Idea 1 Answer

Problem with First Person Shooter Script 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges