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

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