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

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

How to get bullets to hit crosshair 2 Answers

trying to link an aniamtion in one script to a action in another 0 Answers

My player's camera displays jerky objects 2 Answers

How To Convert World/Relative Position for Aim Down Sights? 1 Answer

Animations interupting Aim-Script 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