- Home /
Entering multiple variables into a function
I am making a multiplayergame and i want to record witch played dealt a certan blow of damage by entering the amount of damage and then the damagedealers name. But i dont know how to do it. Heres my code: using UnityEngine; using System.Collections;
public class Explosion : Photon.MonoBehaviour {
public float radius;
public float power;
public float damage;
public float falloff;
public class Damage {
public float damage;
public PhotonPlayer pl;
}
// Update is called once per frame
void Awake () {
Vector3 explosionPos = transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
foreach (Collider hit in colliders) {
if (hit && hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0F);
if (hit.gameObject.tag == "Player") {
AcensionPlayermovement script = hit.gameObject.GetComponent<AcensionPlayermovement>();
float distance = Vector3.Distance(hit.transform.position, transform.position);
//Here i want to send the players name aswell
script.ApplyDamage (damage - (distance /falloff+ distance));
}
}
}
}
and here:
// and here i want to recive that players name
public void ApplyDamage (float Damage){
print(Damage);
Currenthealth =Currenthealth - Damage;
return;
}
thanks in advance for your help!
Answer by 767_2 · Oct 04, 2014 at 03:47 PM
you can pass multiple vars like this
script.ApplyDamage (damage - (distance /falloff+ distance),name);
public void ApplyDamage (float Damage,String name){/* */}
but i think a better approach can be this you should give each player a script that has health variable on it and when a hit happens change its health value
////////player script
public class playerstuff : MonoBehaviour {
public float health;
}
//////////////explosion script
if (hit.gameObject.tag == "Player") {
AcensionPlayermovement script = hit.gameObject.GetComponent<AcensionPlayermovement>();
float distance = Vector3.Distance(hit.transform.position, transform.position);
hit.gameobject.GetComponent<playerStuff>().health-= damage - (distance /falloff+ distance);
}
Thanks. Didnt think that it was possible to pass multiple variables. Dum me i guess :)
Your answer
Follow this Question
Related Questions
Multiple player spawnpoints 0 Answers
Scene changing and multiple spawn points 1 Answer
How to call a variable that was defined in FixedUpdate in javascript 1 Answer
Changing to online sceen in multiplayer 0 Answers
UNet Multiple Characters 0 Answers