基于unity的2d动画制作----基于c#语言开发,类似于《DNF》的2d界面,目前只有一个游戏场景。成果图UI如下图所示
游戏成果视频已经上传B站:
2dAnimation游戏
游戏开发主要步骤:
1.素材收集(来自Unity的Asset Store)
2.UI设计(随心所欲)
3.刚体碰撞规则等(csharp代码)
Hierarchy的整体结构如下:每个物体的名称和它的英文名大概一致。
脚本构造如下:
部分PlayerController的代码如下:
`//author:刘家诚:date:2020.10.16
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//author:刘家诚:date:2020.10.16
public class PlayerController : MonoBehaviour
{
//控制角色的移动,生命,动画等
public float speed = 5f;//移动速度
private int maxHealth = 5;//最大生命值
private int currentHealth;//当前生命值
private float invicibleTime = 2f;//无敌时间
private float invincibleTimer;//无敌计时器
private bool isInvincible;//是否无敌
public GameObject bulletPrefab;//子弹
//=====玩家的朝向=====
private Vector2 lookDirection = new Vector2(1, 0);
//不希望公开,但希望访问属性值
public int MyMaxHealth
{
get
{
return maxHealth;
}
}
public int MyCurrentHealth
{
get
{
return currentHealth;
}
}
Rigidbody2D rbody;
Animator anim;
// Start is called before the first frame update
void Start()
{
//获取刚体组件
rbody = GetComponent<Rigidbody2D>();
currentHealth = 2;//初始生命值
invincibleTimer = 0;
rbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
//Time.deltaTime是计算机渲染一帧所需时间
float moveX = Input.GetAxisRaw(