Unity3d Survival Shooter Tutorial 学习笔记(一)---环境配置和玩家角色

从官网下载工程项目:

https://assetstore.unity.com/packages/essentials/tutorial-projects/survival-shooter-tutorial-40756

新建Sense:Level01

把prefabs文件夹中的Environment和Lights拖到Hierarchy里。

我们需要Camera来观察Sense,由于地面有各种物体,camera到地面的射线并不一致,为方便处理,我们新建一个Quad平面:floor

我们只需要Floor的轮廓,所以把它设为不可见的:删除Mesh Renderer

Layer设置为Floor:

添加音乐效果

Create empty GameObject

选择background music

设置音量大小和循环播放:

添加Player

在Models/Characters文件夹

并设置Player的Tag

 

可以看到,Player有三个状态,对应三个Animation:Move,Idle,Death

我们要创建Animator Controller来建立状态机,命名为PlayerAC,并把PlayerAC拖到Hierarchy的Player里

打开PlayerAC,并把三种状态拖进PlayerAC,把Idle设为默认状态:

 

添加Parameter来控制状态转换:

1.bool IsWalking

2.Trigger Die

(Trigger 类型同样有true和false两个值,不同的是Trigger只触发一次,Trigger变为true后马上变回false)

Make transition:

设置转换条件(Condition):

任何状态都可能死亡,所以我们把Any State 转向Death

给Player添加一个Rigidbody,使其能够进行物理碰撞Physics.

固定y轴,使Player只在xz平面运动,同时固定x和z的旋转,只能绕y轴转(注意y轴朝上!)

为Player添加Capsule,进行碰撞检测

为Player添加Script:PlayerMovement.cs

public class PlayerMovement : MonoBehaviour
{
    public float speed=6f;
    private Rigidbody PlayerRigidbody;
    Animator anim;
    int floorMask;//
    float camRayLength;
     void Awake()//与Start类似,但Awake无论Script是否禁用都可以被调用
    {
        floorMask = LayerMask.GetMask("Floor");
        anim = GetComponent<Animator>();
        PlayerRigidbody = GetComponent<Rigidbody>();
    }
    void FixedUpdate()//每次物理更新时调用
    {
        float moveHorizontal = Input.GetAxisRaw("Horizontal");//GetAxis范围从-1~1, GetAxisRaw只取-1,0,1
        float moveVertical = Input.GetAxisRaw("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        PlayerRigidbody.AddForce(speed * movement);
    }
}

 

float moveHorizontal = Input.GetAxisRaw("Horizontal");//GetAxis范围从-1~1, GetAxisRaw只取-1,0,1
float moveVertical = Input.GetAxisRaw("Vertical");

注意:

"Horizontal","Vertical"都是Unity默认设置的

可以在Unity中查看:

Vertical对应S,W按键,Horizontal对应A,D按键

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Zombie Raid is a thrilling top-down shooter survival game set in a post-apocalyptic world overrun by zombies. The game features fast-paced action, challenging gameplay, and a variety of weapons and power-ups to help you survive. As a survivor, your goal is to protect your base from the endless waves of zombies. You'll need to use your wits and quick reflexes to stay alive and fend off the undead hordes. The game features a variety of weapons, from pistols and shotguns to assault rifles and rocket launchers, to help you take down the zombies. In addition to weapons, you can also collect power-ups like health kits, ammo crates, and special abilities to help you survive. These power-ups can be found scattered throughout the game world, so be sure to explore and scavenge as much as possible. Zombie Raid also features a variety of enemies, from slow-moving zombies to fast and agile ones, as well as bosses that require strategy and skill to defeat. You'll need to adapt to each new wave of enemies and use different tactics to survive. The game also features multiple levels, each with its own unique challenges and objectives. As you progress through the game, you'll unlock new weapons and abilities, making it easier to take on the hordes of zombies. Overall, Zombie Raid is a fun and exciting top-down shooter survival game that will keep you on the edge of your seat. With its challenging gameplay, variety of weapons and power-ups, and endless waves of zombies, it's a game that's sure to keep you entertained for hours on end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值