How to add score when destroy another player with Raycast?
I making some multiplayer deathmatch game that is playing on the same keyboard shared by 3 players. I want to make some scoring sistem, but i dont know: -How could i check which player have destroyed another player?
In the other words: -How could i check who have sent last raycast before target have been destroyed?
Do you have some idea? :))
Answer by Derenger21 · Jul 06, 2016 at 04:38 AM
"same keyboard shared by 3 players" Sounds messy ha ha.
To get a proper answer we'd need to see your code and how attacking one another is set up.
Other than that I, personally, would put a check within the
if (physics.raycast (me, aim, dist, out Hit){
hit.takedamage bla bla
if (!Hit.transform.gameObject.activeInHierarchy){
myScore++;
}
}
or
if (Hit.transform.gameObject.GetComponent<CodeName>().isDead){
myScore++;
}
}
Like I said, hard to answer without more information from you.
Answer by jure006 · Jul 07, 2016 at 05:15 PM
Yes, it's messy a bit and it's playing with left hand only ;) , i love it!
That is a code i was looking for but problem is that it doesn't work, actually nothing happen, even Debug.Log not working after i destroy someone.
This is my shooting function code:
void Shoot() { if (CanShoot()) { Ray ray = new Ray(spawn.position, spawn.forward); RaycastHit hit;
float shootDistance = Random.Range(22, 24);
if (Physics.Raycast(ray, out hit, shootDistance))
{
shootDistance = hit.distance;
hit.transform.SendMessage("Cmd_ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
//hit.transform.SendMessage("BulletRayShoot", TheDamage, SendMessageOptions.DontRequireReceiver);
if (hit.transform.gameObject.GetComponent<Hunter>().isDead || !hit.transform.gameObject.activeInHierarchy)
{
if(gameObject.transform.parent.name == "Player1")
{
Debug.Log("Is anybody out there?"); //guess not...
HudManager.hudManager.WinNumCountP1++;
}
}
}
nextPossibleShootTime = Time.time + secondsBetweenShots;
GetComponent<AudioSource>().Play();
}
Your answer
Follow this Question
Related Questions
Check if position is inside a collider 5 Answers
how do I call a function from another script, when Raycast Hits? 1 Answer
Raycast hit 2 Answers
Highlighting with a Raycast 1 Answer
get array of RaycastAll hits 1 Answer