您的位置:首页 > 移动开发 > Unity3D

Unity 简单手机小游戏 - 3D重力滚球(源码)

2017-08-19 11:49 961 查看
游戏效果图: 需要的可以素材的可以留言,评论,,目前做了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);
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: