《unity 5.x從入門到精通》前四章是一些Unity的情況介紹,第五章開始介紹Unity的基礎操作,第六章通過一個3D場景的實現介紹了3D游戲制作模式的基本操作。
書的第七章可能是因為Unity 4.x 才支持2D游戲,所以用一款小游戲來介紹了2D游戲的制作,並且在這一章第一次出現了C#腳本,因為動畫已經通過Unity 3D內置組件實現,所以下面是使動畫移動的C#代碼。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move : MonoBehaviour { public float speed = 5.0f; void Start () { transform.position = new Vector3(22, 3, 0);//初始化動畫出現位置 } void Update () { if (transform.position.x > -22) { transform.Translate(Vector3.left * speed * Time.deltaTime);//設定一定條件,使動畫從右向左移動 } else { transform.position = new Vector3(22, 3, 0);//超出-22的界限后,初始化動畫位置 } } }
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。