using UnityEngine; using System.Collections; public class PlayerCollision : MonoBehaviour { private bool isHit; private EnemyAI enemyStats; private PlayerStats playerStats; void Start(){ isHit = false; enemyStats = GameObject.Find ("Enemy").GetComponent<EnemyAI> (); playerStats = GameObject.Find ("Player").GetComponent<PlayerStats> (); } /* * All player interactions handled here */ void OnTriggerEnter2D(Collider2D col){ if (isHit == true) { // If hit recently, don't register hits return; } if (isHit == false) { if (col.tag == "enemyWeapon") { // Enemy hits with slash attack Debug.Log ("player hit by slash"); isHit = true; playerStats.Damage (5); // player.knockback StartCoroutine (ExecuteAfterTime (1)); } if (col.tag == "enemyKick") { // Enemy hits with kick attack Debug.Log ("player hit by kick"); isHit = true; playerStats.Damage (2); // player . shield broke // Check if shielding in other script StartCoroutine (ExecuteAfterTime (1)); } if (col.tag == "projectile") { Debug.Log ("Player hit by projectile!"); isHit = true; playerStats.Damage (5); StartCoroutine (ExecuteAfterTime (0.5f)); } } } /* * After parameter time, sets player hitable again */ IEnumerator ExecuteAfterTime(float time){ yield return new WaitForSeconds (time); isHit = false; Debug.Log ("Player is able to get hit again!"); } }