UNITY3D学习笔记5
2015-07-24 14:20
926 查看
using UnityEngine; using System.Collections; public class TestD4 : MonoBehaviour { GameObject objCube; GameObject objShere; bool isCubeRoate,isShereRoate; // Use this for initialization void Start () { //objCube = GameObject.Find("Cube"); objCube = GameObject.FindWithTag("MyTag"); objShere = GameObject.Find("Object/Sphere"); } // Update is called once per frame void Update () { if(isCubeRoate){ if(objCube){ objCube.transform.Rotate(0.0f,Time.deltaTime*200,0.0f); } } if(isShereRoate){ if(objShere){ objShere.transform.Rotate(0.0f,Time.deltaTime*200,0.0f); } } } void OnGUI(){ if(GUILayout.Button("cube rotate",GUILayout.Height(50))){ if(!isCubeRoate){ isCubeRoate = true; }else{ isCubeRoate = false; } } if(GUILayout.Button("sphere rotate",GUILayout.Height(50))){ if(!isShereRoate){ isShereRoate = true; }else{ isShereRoate = false; } } if(GUILayout.Button("destroy",GUILayout.Height(50))){ Destroy(objCube); Destroy(objShere); } } }
using UnityEngine; using System.Collections; public class TestD5 : MonoBehaviour { GameObject obj; // Use this for initialization void Start () { obj = GameObject.Find("Sphere"); } // Update is called once per frame void Update () { } void OnGUI(){ if(GUILayout.Button("start copy",GUILayout.Height(50))){ GameObject clone = Instantiate(obj,obj.transform.position,obj.transform.rotation) as GameObject; Destroy(clone,5); } } }
using UnityEngine; using System.Collections; public class TestD6 : MonoBehaviour { GameObject objCube,objCylinder; int speed = 150; // Use this for initialization void Start () { objCube = GameObject.Find("Cube"); objCylinder = GameObject.Find("Cylinder"); } // Update is called once per frame void Update () { objCube.transform.RotateAround(objCylinder.transform.position,Vector3.up,Time.deltaTime*speed); } void OnGUI(){ GUILayout.Label("cube rotate dgree:"+objCube.transform.rotation); GUILayout.Label("cube position:"+objCube.transform.position); } }
using UnityEngine; using System.Collections; public class TestD7 : MonoBehaviour { GameObject obj; float scaleX = 1.0f; float scaleY = 1.0f; float scaleZ = 1.0f; // Use this for initialization void Start () { obj = GameObject.Find("Cube2"); } // Update is called once per frame void Update () { } void OnGUI(){ GUILayout.Label("scale X"); scaleX = GUILayout.HorizontalSlider(scaleX,1.0f,2.0f,GUILayout.Width(100)); GUILayout.Label("scale Y"); scaleY = GUILayout.HorizontalSlider(scaleY,1.0f,2.0f,GUILayout.Width(100)); GUILayout.Label("scale Z"); scaleZ = GUILayout.HorizontalSlider(scaleZ,1.0f,2.0f,GUILayout.Width(100)); obj.transform.localScale = new Vector3(scaleX,scaleY,scaleZ); } }
using UnityEngine; using System.Collections; public class TestD8 : MonoBehaviour { // Use this for initialization //void Start () { } // Update is called once per frame void Update () { } IEnumerator Start(){ /*Debug.Log ("Time.time:"+Time.time); yield return new WaitForSeconds(2); Debug.Log ("Time.time:"+Time.time);*/ return Test (); } IEnumerator Test(){ Debug.Log ("Time.time:"+Time.time); yield return new WaitForSeconds(2); Debug.Log ("Time.time:"+Time.time); } void OnGUI(){ GUILayout.Label("Now Game Time:Time.time:"+Time.time); GUILayout.Label("previous frame time:Time.deltaTime:"+Time.deltaTime); GUILayout.Label("fixed increment time:Time.fixedTime:"+Time.fixedTime); GUILayout.Label("previous time:Time.fixedDeltaTime:"+Time.fixedDeltaTime); } }
相关文章推荐
- Unity之简单的机器人AI状态改变
- [UnityUI]一些有趣的UI例子
- unity Bug(1)UnityEditor.UI.dll' is in timestamps but is not known in assetdatabase
- 浅尝Unity 3D的Asset Bundle知识(五)-----缓存利用篇
- Unity3D教程:实现基于Socket通讯的公共聊天室
- Unity3d摄影机晃动特效【C#脚本】
- Unity 鼠标拖动场景内的物体
- Unity官方教程学习笔记之Roll A Ball篇---(二)创建地面
- Unity3D学习笔记-----2015-07-24(GUI---01)
- Unity 播放 视频
- 使用zip包离线安装Android SDK,并使用Unity发布apk
- Unity官方教程学习笔记之Roll A Ball篇---(一)创建工程和保存场景
- Unity3D:延时方法Invoke和InvokeRepeating
- Unity3D:HideInInspector和SerializeField
- Unity3D:Script 脚本所有编译器属性详解
- 最近整理Unity4.x 项目升级Unity5.0 过程中出现的各种常见问题,与大家共享。
- unity3d协程方法停止不了
- unity碰撞组件、刚体组件
- unity3d打包和包的使用
- UNITY3D学习笔记4