虚幻4 ue4 学习笔记pwan篇 1.1a 创建spherecomponent与boxcomponent 物体组件

 1 //本代码只有cpp部分 没有在头文件添加任何代码
 2 // Fill out your copyright notice in the Description page of Project Settings.
 3 
 4 #include "MyPawn.h"
 5 
 6 #include "Runtime/Engine/Classes/Components/BoxComponent.h"//    UBoxComponent 引用
 7 #include "Runtime/Engine/Classes/Components/SphereComponent.h"//    USphereComponent 引用
 8 // Sets default values
 9 AMyPawn::AMyPawn()
10 {
11      // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
12     PrimaryActorTick.bCanEverTick = true;
13 
14     //CreateDefaultSubobject ue4所有组件都是通过这个函数创建的
15     //<USphereComponent>与<UBoxComponent> 告诉CreateDefaultSubobject要返回对象的类型是什么 
16     //虚幻4所有对象都有CreateDefaultSubobject方法 
17 
18     UBoxComponent *BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent2"));//创建一个正方体组件 RootCompont 是蓝图里面显示的名称 名称随意
19     USphereComponent* SphereComponent = this->CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));//创建一个圆球组件 RootCompont 是蓝图里面显示的名称 名称随意
20     /*Vectoe是虚幻4中的向量类*/
21 }
22 
23 // Called when the game starts or when spawned
24 void AMyPawn::BeginPlay()
25 {
26     Super::BeginPlay();
27     
28 }
29 
30 // Called every frame
31 void AMyPawn::Tick(float DeltaTime)
32 {
33     Super::Tick(DeltaTime);
34 }
35 
36 // Called to bind functionality to input
37 void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
38 {
39     Super::SetupPlayerInputComponent(PlayerInputComponent);
40 
41 }

 

spherecomponent与boxcomponenet 是实现物理碰撞的必要组件

转载于:https://www.cnblogs.com/gobai/p/8001379.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值