Hit Any Collider
Unreal
APlayerChar::APlayerChar() { GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &APlayerChar::OnCompHit); }//if not working the AddDynamic Function delegate use on BeginPlay()
void APlayerChar::OnCompHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { //CurrentJumpCount = 0;
if(OtherComp != this && OtherComp != NULL) UE_LOG(LogTemp, Warning, TEXT("Collision On Component"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("I Hit: %s"), *OtherComp->GetName())); }
Unity
[SerializeField] string collisioName;
void OnCollisionEnter(Collision collision) => collisioName = collision.gameObject.name;
private void OnGUI() => GUI.Label(new Rect(10, 10, 100, 20), "collision Name = " + collisioName);
Comments
Post a Comment