Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .cpp
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "Player_Character.h"
- #include "Components/SkeletalMeshComponent.h"
- #include "Components/CapsuleComponent.h"
- #include "Camera/CameraComponent.h"
- #include "GameFramework/SpringArmComponent.h"
- APlayer_Character::APlayer_Character()
- {
- SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArma"));
- if (SpringArm)
- {
- SpringArm->SetupAttachment(GetCapsuleComponent());
- SpringArm->RelativeLocation = FVector(-20.0f, 0.0f, 40.0f);
- SpringArm->TargetArmLength = 0.0f;
- SpringArm->bDoCollisionTest = false;
- SpringArm->bUsePawnControlRotation = true;
- SpringArm->bInheritPitch = false;
- SpringArm->bInheritRoll = true;
- SpringArm->bInheritYaw = true;
- }
- Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
- if (Camera)
- {
- Camera->FieldOfView = 90.0f;
- Camera->SetupAttachment(SpringArm, USkeletalMeshComponent::SocketName);
- }
- FP_Mesh = CreateDefaultSubobject <USkeletalMesh>(TEXT("FP_Mesh"));
- if (FP_Mesh)
- {
- FP_Mesh->SetupAttachment(Camera);
- }
- GunMesh = CreateDefaultSubobject <USkeletalMesh>(TEXT("GunMesh"));
- if (GunMesh)
- {
- GunMesh->SetupAttachment(Camera);
- }
- MaxHealth = 100.0f;
- CurrentHealth = MaxHealth;
- bCanShoot = true;
- bUnlimitedAmmo = false;
- MaxAmmo = 10;
- CurrentAmmo = MaxAmmo;
- }
- void APlayer_Character::BeginPlay()
- {
- Super::BeginPlay();
- // For when the ammo value was changed
- if (CurrentAmmo != MaxAmmo)
- {
- CurrentAmmo = MaxAmmo;
- }
- }
- void APlayer_Character::SetupPlayerInputComponent(UInputComponent * PlayerInputComponent)
- {
- Super::SetupPlayerInputComponent(PlayerInputComponent);
- //Assertion Check
- check(PlayerInputComponent);
- }
- void APlayer_Character::OnDeath_Implementation()
- {
- }
- .h
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "CoreMinimal.h"
- #include "Base_Character.h"
- #include "Components/SkeletalMeshComponent.h"
- #include "Camera/CameraComponent.h"
- #include "Player_Character.generated.h"
- /**
- *
- */
- UCLASS()
- class CPP_PACKT_API APlayer_Character : public ABase_Character
- {
- GENERATED_BODY()
- UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
- class USpringArmComponent* SpringArm;
- UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
- class UCameraComponent* Camera;
- // This would be for our arms mesh
- UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
- class USkeletalMeshComponent* FP_Mesh;
- UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
- class USkeletalMeshComponent* GunMesh;
- public:
- // Constructor
- APlayer_Character();
- UFUNCTION(BlueprintPure, Category = "Character|Gun|Ammo")
- int32 GetCurrentAmmo() const { return CurrentAmmo; }
- UFUNCTION(BlueprintPure, Category = "Character|Gun|Ammo")
- int32 GetMaxAmmo() const { return MaxAmmo; }
- UFUNCTION(BlueprintCallable, Category = "Character|Gun|Ammo")
- void SetCurrentAmmo(int NewAmmo) { CurrentAmmo = NewAmmo; }
- protected:
- virtual void BeginPlay() override;
- virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)override;
- virtual void OnDeath_Implementation() override;
- // Check if we have any remaining ammo
- bool HasAmmo() const { return (CurrentAmmo > 0); }
- // Flag for when the player can shoot
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character|Gun")
- bool bCanShoot;
- // Flag for when the player can shoot unlimited amount of bullets.
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character|Gun|Ammo")
- bool bUnlimitedAmmo;
- int CurrentAmmo;
- UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Character|Gun|Ammo")
- int MaxAmmo;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement