void ResetEnemy(GameObject enemy) { TrooperBehaviour trooper = enemy.GetComponent <TrooperBehaviour>(); BoxCollider enemyCollider = enemy.GetComponent <BoxCollider>(); NavMeshAgent enemyNavMesh = enemy.GetComponent <NavMeshAgent>(); enemy.SetActive(true); // Set trooper as active so the scripts can be adjusted enemyNavMesh.enabled = false; // Disable their NavMesh so they can be teleported through walls enemy.transform.SetPositionAndRotation(transform.position, enemy.transform.rotation); // Set their position to the object the script is attached to trooper.currentHealth = trooper.reviveHealthGain; // Reset their health trooper.xIsDeadX = false; trooper.xIsDownedX = false; trooper.currentState = TrooperBehaviour.trooperState.doorSpawn; // Change their AI state enemyCollider.enabled = true; enemyNavMesh.enabled = true; }
// When the enemy hits the player, the player takes damage void OnCollisionEnter(Collision other) { Debug.Log("Collision"); Vector3 playerHitDirection = other.transform.forward /*other.transform.position - transform.position*/; playerHitDirection = playerHitDirection.normalized; if (other.gameObject.tag == "EnemySword") { TrooperBehaviour enemy = other.gameObject.GetComponentInParent <TrooperBehaviour>(); if (enemy.xIsDownedX == false) { playerWasDamaged = true; KnockBack(playerHitDirection); currentHealth -= enemy.enemyAttackStrength; } } }