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 _= disableOnDeath*.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*.enabled = false;
}*_
* //Disable GameObjects*
* for (int i = 0; i < disableGameObjectsOnDeath.Length; i++)*
* {*
_ disableGameObjectsOnDeath*.SetActive(false);
}*_
* //Disable the collider*
* Collider _col = GetComponent();
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().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_.enabled = wasEnabled*;
}*_
* //Enable the gameobjects*
* for (int i = 0; i < disableGameObjectsOnDeath.Length; i++)*
* {*
_ disableGameObjectsOnDeath*.SetActive(true);
}*_
* //Enable the collider*
* Collider _col = GetComponent();
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;*
}
}