- Home /
deathmatch point system
for my splitscreen shooter I want the player to be able to score points if they kill another player, at the moment when the players die they drop yellow point cubes, how would I change my player health script to add one point to the killer's killcount?
this is the healthscript I'm using, it's in Javascript
var PointCube : Transform; var spawneffect : Transform; var SpawnPoint : Transform; var respawn : boolean = false; var health:float = 90;
function Damage(dmg:float){ health -= dmg; }
function Update (){ if(health <=0){
Instantiate (PointCube,transform.position,transform.rotation);
transform.position = SpawnPoint.position;
Instantiate (spawneffect,transform.position,transform.rotation);
var audio: AudioSource = GetComponent.(); audio.Play(); audio.Play(44100);
health += 100; }
}
Answer by sandeepsmartest · Jul 20, 2017 at 08:01 AM
void Damage(float Dmg)
{
health -= Dmg;
if(health<=0)
{
//instantiation stuff
//if you are sure about the killer who killed this player
// increase killer's kill count here simply by taking an instance of the killer script and accessing the value of it
//or declare killer script here in your "myplayer.cs" and drag drop the gameobject on which killer script attached and use the reference variable to increase count(killerscript.killcount+=1)
////if you are NOT sure about the killer who killed this player
//pass the player id along with dmg value to this function and based on the player id , increase kill count to the respective player
// or pass the gameobject to this method along with dmg and getcomponent killerscirpt from the gameobject that you passed and access the killcount value
//or simple the killerscript to this method along with dmg access the killcount value
//Make sure your killerscript conists of the variable killcount with public as accessmodifier
}
}
Hope this may help you. -Nsks
Your answer
Follow this Question
Related Questions
A [Photon] PvP Script. 0 Answers
My script adds +1 to variable only one time 1 Answer
Help on kill counter script! 0 Answers