public void ModHealth(float givVal) { if (Time.time > nextDamage) { if (givVal < 0) { Instantiate(explosionRef, transform.position, transform.rotation); camShaker.AddCustomShake(-transform.up * 3, CameraShake.ShakeType.PLAYERDAM); StartCoroutine(PrevHealthStart(givVal)); } nextDamage = Time.time + nextDamageDelay; hp += givVal; hp = Mathf.Clamp(hp, 0, 100); if (givVal > 0) { prevHealth = hp; prevHealthBar.fillAmount = scaleToHP(hp); healthbar.fillAmount = scaleToHP(hp); } //Visuals Debug.Log(Mathf.RoundToInt((hp / maxHp) * totalStates)); currState = Mathf.RoundToInt((hp / maxHp) * totalStates); body.sprite = damagedSprites[currState]; if (mainCam != null) { painSrc.PlayOneShot(hitSnds[Random.Range(0, hitSnds.Length)]); mainCam.SendMessage(hitMessage, 0.3f); } if (hp <= 0) { deadHudMsg.SetActive(true); Destroy(camShaker); Destroy(camHolder); mainCam.transform.parent = null; mainCam.GetComponent <CheckRestar>().enabled = true; Instantiate(deadSprite, transform.position, transform.rotation); //StartCoroutine(checkrestart()); gameObject.SendMessage(deathMessage, hp); Destroy(gameObject); } else if (hp > 100) { hp = 100; } } healthbar.fillAmount = scaleToHP(hp); // GrainChange(); }