UNITY3D学习笔记5

来源:互联网 发布:大司马淘宝店 编辑:程序博客网 时间:2024/06/06 04:35



using UnityEngine;using System.Collections;public class TestD4 : MonoBehaviour {GameObject objCube;GameObject objShere;bool isCubeRoate,isShereRoate;// Use this for initializationvoid Start () {//objCube = GameObject.Find("Cube");objCube = GameObject.FindWithTag("MyTag");objShere = GameObject.Find("Object/Sphere");}// Update is called once per framevoid 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 initializationvoid Start () {obj = GameObject.Find("Sphere");}// Update is called once per framevoid 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 initializationvoid Start () {objCube = GameObject.Find("Cube");objCylinder = GameObject.Find("Cylinder");}// Update is called once per framevoid 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 initializationvoid Start () {obj = GameObject.Find("Cube2");}// Update is called once per framevoid 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 framevoid 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);}}


0 0
原创粉丝点击