Unity 2D Game Developer Course Farming RPG

1. Introduction

1. Course Introduction




2. Preparation

1. Unity and Visual Studio Installation

2. SourceTree Installation and Using SourceTree With The Supplied Unity Project

3. Game Architecture and Course Structure Overview

4. Project Setup

1. Project Creation


需要安装的插件((windows->package manager))

在unity商店才能看到未安装的插件

导入课程资源包

setting


scene

创建相机

virtual camera -> lens -> Orthographic Size

Main Camera -> add components -> pixel perfect

2. Review Custom Package

动画控制器, 点击可打开动画编辑emptyempty
选项卡里出现了关联
empty
top和trunk添加sprite renderer

bug解决, 将虚拟相机z设为-20, 运行游戏就能看见树了
点击左侧的parameter项可以改变状态, 然后触发动画
把这个tree组件拖动到prefabs, 成为预制件可复用
把树删了

5. Player Basics

1. Player Gameobject Set-Up

emptyempty->add component->sprite renderer

复制body->hair
复制hair->hat->3


添加刚体
添加sort组添加为预制件
因为在sort组里, 所以在组里进行了排序
取消sort组的效果
一个sort组排序一个不开sort组排序的效果相机跟随
预制件的tag改为player

2. Player Class and Abstract Singleton Class

单例抽象类

using UnityEngine;

public abstract class SingletonMonobehaviour<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T _instance;

    public static T Instance
    {
        get { return _instance; }
    }

    protected void Awake()
    {
        if (_instance == null)
        {
            _instance = this as T;
        }
        else
        {
            // 销毁之前的实例
            Destroy(gameObject);
        }
    }
}

附加脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : SingletonMonobehaviour<Player>
{
    
}

创建两个player实例因为脚本继承了单例抽象类, 所以其中一个被删除了

3. Player Animation Controllers

player右键unpackage, 删除预制件
对应的动画控制器移动到对应的animator选项卡
下拉菜单查看动画列表, 点击切换预览, 再点击播放按钮可以播放可以看出此时身体还没有成为一块

创建scripts/animation/MovementAnimationParameterController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovementAnimationParameterController : MonoBehaviour
{
    private void AnimationEventPlayFootstepSound()
    {
         
    }
}

脚本加到对象上


  目录