Unity 简单手机小游戏

来源:互联网 发布:柠檬tv网络电视 编辑:程序博客网 时间:2024/06/06 14:01

游戏效果图: 需要的可以素材的可以留言,评论,,目前做了5个关卡

码云:https://gitee.com/Czhenya/GunNiGeQiu



通过陀螺仪使得小球有运动的力

public class groy : MonoBehaviour {        float x;        float y;        Gyroscope go;        void Start()        {            go = Input.gyro;            go.enabled = true;        }        void Update()        {            x = Input.acceleration.x;            y = Input.acceleration.y;            this.GetComponent<Rigidbody>().AddForce(new Vector3(-x, 0, -y) * 20);        }}

开始的UI场景,应用于按钮(开始,和游戏结束)

public class StartUi : MonoBehaviour {    public void Reaply()    {        Time.timeScale = 1;        Application.LoadLevel(1);           }    public void Quit()    {        Application.Quit();    }}

用触发器时刻判断,进洞重新开始,到终点弹出重玩,下一关按钮进行选择,用GUI制作了简易放回主菜单(回到场景0)按键,,

public class Mover : MonoBehaviour {    public GameObject go;      private void OnTriggerStay(Collider other)    {        if (other.name == "target")        {            go.gameObject.SetActive(true);            Time.timeScale = 0;        }        else        {            Application.LoadLevel(1);        }    }    private void OnTriggerEnter(Collider other)    {        if (other.name == "target")        {            go.gameObject.SetActive(true);            Time.timeScale = 0;        }        else        {            Application.LoadLevel(1);        }    }    private void OnGUI()    {        GUIStyle style = new GUIStyle();        style.fontSize = 36;        if (GUI.Button(new Rect(50,30, 200,80 ), "返回菜单",style)){            Application.LoadLevel(0);        }              }}