protected virtual void OnCollisionEnter2D(Collision2D collision) { GameObject collidedObject = collision.gameObject; Rigidbody2D throwableObjectBody = collidedObject.GetComponent <Rigidbody2D>(); if (collidedObject.tag.Equals("Throwable")) { charAnimator.SetBool("takingDamage", true); ThrowableController throwableController = collidedObject.GetComponent <ThrowableController>(); damage = throwableController.GetDamage(); TurnToAttacker(collidedObject); TakeDamage(damage); } }
public void Throw(Vector2 throwDestination) { if (throwTimer > 0) { Debug.Log("Cooling down."); return; } throwTimer = throwResetTimer; Debug.Log("Throwing bomb to " + throwDestination); //Instantiate(bomb, throwOrigin.position, throwOrigin.rotation); GameObject newThrowable = Instantiate(throwable, throwOrigin.position, throwOrigin.rotation); thrownObject = newThrowable.GetComponent <ThrowableController>(); thrownRB = newThrowable.GetComponent <Rigidbody2D>(); newThrowable.GetComponent <ThrowableController>().throwableRigidbody = newThrowable.GetComponent <Rigidbody2D>(); newThrowable.GetComponent <ThrowableController>().SetThrowDestination(throwDestination); }