效果图
实现步骤要点:
1、添加Cube游戏
2、创建预设对象
3、创建空游戏对象,用于绑定执行预设代码
4、选中gameObject在Inspector检查器中添加和绑定以下代码
using UnityEngine; using System.Collections; public class prefab : MonoBehaviour { public GameObject ViewCenter; private float i=-10.0f; // Use this for initialization void Start () { } // Update is called once per frame(Pre, transform.position, transform.rotation); void Update () { if (i < 1f) { i++; } GameObject instance=Instantiate(ViewCenter,transform.position*i,transform.rotation) as GameObject; } }
方法一:通过检查器直接获取预设对象
方法二:代码获取,把代码修改
using UnityEngine; using System.Collections; public class prefab : MonoBehaviour { public GameObject ViewCenter; private float i = -10.0f; // Use this for initialization void Start () { ViewCenter = GameObject.Find ("gameObject"); } // Update is called once per frame(Pre, transform.position, transform.rotation); void Update () { if (i < 1f) { i++; } GameObject instance = Instantiate (ViewCenter, transform.position * i, transform.rotation) as GameObject; } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。