I’m making a fighting game and I had set up a code
public class Fight : MonoBehaviour {
public float Damage=60;
public List<Transform> HitList;
private bool hit;
public bool YouWon;
public bool ko;
private bool dealdamage;
internal Animator animator; //stores the animator component
float v; //vertical movements
float h; //horizontal movements
float straight;
float hook;
float block;
float body;
float jump;
float left;
float right;
float high;
float wide;
void Start (){
animator = GetComponent<Animator>(); //assigns Animator component when we start the game
}
void Update (){
v = Input.GetAxis("Vertical");
h = Input.GetAxis("Horizontal");
straight = Input.GetAxis("Straight");
hook = Input.GetAxis("Hook");
high = Input.GetAxis("Guard Height");
wide = Input.GetAxis("Guard Width");
block = Input.GetAxis("Block");
body = Input.GetAxis("Body");
TurnLeft();
TurnRight();
Jump();
Stats php=(Stats)GetComponent("Stats");
if(php){
if(php.CurrentHealth<=0)ko=true;
}
//LETS DO SOME KILLIN!
if(hit){
if(HitList.Count>0&dealdamage){
int ls=HitList.Count;
for (int i = 0; i < ls; i++){
Stats hp=(Stats)HitList*.transform.GetComponent("Stats");*
-
hp.CurrentHealth=hp.CurrentHealth-Damage;*
-
if(hp.KO){}*
-
}*
-
dealdamage=false;*
-
}*
-
}*
-
}*
-
void FixedUpdate (){*
-
//set the "Walk" parameter to the v axis value*
-
animator.SetFloat ("Walk", v);*
-
animator.SetFloat ("Turn", h);*
-
animator.SetFloat ("Straight", straight);*
-
animator.SetFloat ("Hook", hook);*
-
animator.SetFloat ("Block", block);*
-
animator.SetFloat ("Body", body);*
-
animator.SetFloat("Turn Left", left);*
-
animator.SetFloat("Turn Right", right);*
-
animator.SetFloat("Guard Height", high);*
-
animator.SetFloat("Guard Width", wide);*
-
animator.SetFloat("Jump", jump);*
-
}*
-
void TurnLeft (){*
-
if(Input.GetButton("Turn Left")) {*
-
left = 0.2f;*
-
}*
-
else {*
-
left = 0.0f;*
-
}*
-
}*
-
void TurnRight (){*
-
if(Input.GetButton("Turn Right")) {*
-
right = 0.2f;*
-
}*
-
else {*
-
right = 0.0f;*
-
}*
-
}*
-
void Jump (){*
-
if(Input.GetButton("Jump")) {*
-
jump = 0.2f;*
-
}*
-
else {*
-
jump = 0.0f;*
-
}*
-
}*
-
void OnCollisionEnter(Collider other){*
-
//ADD AIS TO LIST TO INFLICT DAMAGE IF IN RANGE*
-
Health AI=(Health)other.transform.GetComponent("Health");*
-
if(AI){*
-
HitList.Add(other.transform);*
-
}*
-
}*
-
void OnCollisionExit(Collider other){*
-
//REMOVE FROM LIST WHEN OUT OF RANGE*
-
Health AI=(Health)other.transform.GetComponent("Health");*
-
if(AI){*
-
HitList.Remove(other.transform);*
-
}*
-
}*
-
void OnGUI(){*
-
//HEALTH BAR AND AI COUNT*
-
Health php=(Health)GetComponent("Health");*
-
if(php){*
-
float hpp=php.CurrentHealth;*
-
GUI.Button(new Rect(0, 30, 300, 26), "Health: "+hpp);*
-
}*
-
//YOU WON!*
-
if(YouWon){*
-
GUI.Box(new Rect(200, 200, 330, 260), "Congratulations! You have defeated all the Evil Skellies!");*
-
if(GUI.Button(new Rect(310, 400, 120, 26), "Continue Playing"))YouWon=false;*
-
}*
-
}*
}
How can I get the fighter to detect enemy collision?