学习Unity脚本推荐:Unity3D官网索引
首先一点,你要确保有一个想要跳转的目标场景。在本案例中,目标场景是ending。
第一步:创建一个碰撞体,放置在需要的触发场景跳转的位置
![](https://img-my.csdn.net/uploads/201301/21/1358771818_2242.jpg)
第二步:删除多余的脚本,并且新建自己的脚本:
![](https://img-my.csdn.net/uploads/201301/21/1358772216_7470.jpg)
第三步:查阅相关文档,具体网址参见上篇博文:
![](https://img-my.csdn.net/uploads/201301/21/1358772612_9510.jpg)
第四步:将如下代码复制到你的脚本中:
// loadLevel.js
// This is used to load a level set in the inspector
var level:String; // Then anything you type will not be run
function Update () {
}
function OnTriggerStay (theCollider : Collider) {
Application.LoadLevel (level);
}
第五步:此时再将Inspector面板中的level字符串改成ending:
![](https://img-my.csdn.net/uploads/201301/21/1358773039_8617.jpg)
这样做的好处是不用每次都新建脚本文件实现跳转,一个脚本就实现了跳转功能。