//When the shield ability is enabled/spawned it will prevent damage for the player with the shield active private void OnEnable() { carInfo = GetComponentInParent <CarInfo>(); addDamage = GetComponentInParent <AddDamageBasedOnForce>(); addForce = GetComponentInParent <AddForceBasedOnHealth>(); addDamage.enabled = false; addForce.enabled = false; carInfo.carStats.isShieldEnabled = true; }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) { carInfo = other.gameObject.GetComponent <CarInfo>(); addForce = other.gameObject.GetComponent <AddForceBasedOnHealth>(); if (!carInfo.carStats.isShieldEnabled) { addForce.ApplyNonCollisionForceVector(transform.up * forceAmount); carInfo.carStats.health += forceAmount; //rigidbody = other.gameObject.GetComponent<Rigidbody>(); //rigidbody.AddForce(transform.up * forceAmount, ForceMode.Impulse); } GameObject clonedExplosion = Instantiate(explosion, transform.position, transform.rotation); Destroy(this.gameObject); } }