//Handles the damage aspect of the weapon by damaging the other player public void attack() { GetComponent <Animator>().Play("Attack"); if (touchingEnemy) { if (collision == null) { touchingEnemy = false; } else { JustinPlayerStats jPS = collision.GetComponent <JustinPlayerStats> (); if (jPS == null) { //Damage enemy code here collision.GetComponent <JustinPlayerStatsNN> ().updateHealth(-damage); } else { //Damage enemy code here jPS.updateHealth(-damage); } //Debug.Log("Enemy was hit! " + collision.GetComponent<JustinPlayerStats>().health); } } GetComponent <Animator>().SetBool("Attacking", false); }
//Spawns a raycast in the bullet to detect for collisions void SpawnRay() { Vector2 direction = Vector2.right; if (!facingRight) { direction = Vector2.left; } RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, bulletBody.velocity.x); if (hit.collider != null && timePassed > lastCollision + 0.00001f) { if (hit.transform.gameObject.tag == "Ground") { Destroy(gameObject); } else if (hit.transform.gameObject.tag == enemyTag) { JustinPlayerStats jPS = hit.transform.gameObject.GetComponent <JustinPlayerStats> (); if (jPS == null) { //Damage enemy code here hit.transform.gameObject.GetComponent <JustinPlayerStatsNN> ().updateHealth(-damage); } else { //Damage enemy code here jPS.updateHealth(-damage); } //Debug.Log("Enemy was hit! " + collidedWith.GetComponent<JustinPlayerStats>().health); Destroy(gameObject); } lastCollision = timePassed; } }