void Update() { float healthFill = Util.remapRange(health, 0, stats.maxHealth, 0, 1); healthUI.fillAmount = healthFill; healthText.text = Health.ToString("#00.0"); if (health < stats.maxHealth && health > 0) { if (!vulnerable) { Health = health + stats.healthRegenRate; } } if (health <= 0) { respawn.RespawnPlayer(gameObject); if (gameObject.GetComponent <TeamAssignment> ().myTeam == TeamAssignment.Team.TEAM_A) { gameObject.SetActive(false); TeamManager.p1CanSwitch = true; } else { gameObject.SetActive(false); TeamManager.p2CanSwitch = true; } health = stats.maxHealth; } }
void CheckIfKilled(int killerPnum, bool tipKill) { if (health <= 0) { transform.gameObject.SetActive(false); BS.transform.position = transform.position; // more elaborate effects for the tip kill Debug.Log(tipKill); if (tipKill) { BS.EmitParticles(125, 1, 2f, 1.5f); } else if (killerPnum != -2) { BS.EmitParticles(50); } if (killerPnum == -1) { // suicice SS.DecrementKills(PCS.GetPlayerNumber()); } else { SS.IncrementKill(killerPnum); } RS.RespawnPlayer(3f, PCS.GetPlayerNumber()); } }
void OnCollisionEnter(Collision col) { if (col.transform.tag == "Deflector") { print("collided with pivot"); Vector3 hitPos = col.contacts [0].point; rb.velocity = Vector3.Reflect(hitPos - transform.position, col.contacts[0].normal) * bulletPower; } if (col.transform.tag == "Wall") { ResetProjectileStatus(); Destroy(gameObject); } if (col.transform.tag == "Player") { PlayerStats stats = col.gameObject.GetComponent <PlayerStats> (); if (col.gameObject != player.gameObject) { if (!col.gameObject.GetComponent <HealthScript> ().vulnerable) { if (col.gameObject.GetComponent <HealthScript> ().Health - player.projectilePower * stats.projDamage > 0) { col.gameObject.GetComponent <HealthScript> ().Health -= player.projectilePower * stats.projDamage; } else { respawn.RespawnPlayer(col.gameObject); col.gameObject.SetActive(false); } } else { col.gameObject.GetComponent <HealthScript> ().Health -= player.projectilePower * stats.projDamage; } ResetProjectileStatus(); Destroy(gameObject); } } }