基于unity的2d影片制作----基于c#語言開發,類似于《冒險島》,只有一個游戲場景,成果圖UI如圖1所示,游戲成果視頻已經上傳B站:https://www.bilibili.com/video/BV1Cr4y1c75W
2dAnimation

圖1
素材來源:Unity的Asset Store,Asset Store里包含許多開源庫,
主要game的物件如右圖所示:
主要用到的腳本有:
player的腳本主要代碼如下:`
//author:劉家誠, last time:2020.10.15
private float x;
private float y;
public float speed = 5;
private Rigidbody2D _rigidbody_2D;
private Animator _animator;
// Start is called before the first frame update
void Start()
{
//2d的組件
_rigidbody_2D = GetComponent<Rigidbody2D>();
_animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
x = Input.GetAxis("Horizontal");
y = Input.GetAxis("Vertical");
//正方向行走
if(x > 0)
{
_rigidbody_2D.transform.eulerAngles = new Vector3(0,0,0);
_animator.SetBool("run", true);
}
//反方向行走
if(x < 0)
{
_rigidbody_2D.transform.eulerAngles = new Vector3(0, 180, 0);
_animator.SetBool("run", true);
}
if(x < 0.001f && x > -0.001f)
{
_animator.SetBool("run", false);
}
Run();
}
private void Run()
{
Vector3 movement = new Vector3(x, y, 0);
_rigidbody_2D.transform.position += movement * speed * Time.deltaTime;
}
//player碰撞檢測用player做,并且要設定tag
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Spike")
{
//如果碰撞到障礙物,那么player消失即可,并且呼叫GameController的ShowGameOverPanel方法
GameController.Instance.ShowGameOverPanel();
Destroy(gameObject);
}
}
`
專案網盤鏈接地址,之后會傳到github上:鏈接:https://pan.baidu.com/s/1lxSTiGQdZ-0Ji6B0z2XMMw
提取碼:jc60
復制這段內容后打開百度網盤手機App,操作更方便哦–來自百度網盤超級會員V3的分享
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/174568.html
標籤:其他
上一篇:移動開發技術1:微信頁面的實作
