1、using UnityEngine; using System.Collections; //本脚本实现用鼠标中键进行缩放和旋转对象 public class CamerZoomRotateObject : MonoBehaviour { //控制相机视角实现拉近或远离物体 private float minFov = 5f;//视角最小值 private float maxFov = 180f;//视角最大值 private float sensitivity =10f;// //旋转快慢控制 private float hspeed=6.0f;
2、 private float vspeed=6.0f; public Transform target; void Start(){ } void Update() { float fov = Camera.main.fieldOfView; fov += Input.GetAxis("Mouse ScrollWheel") * sensitivity; fov = Mathf.Clamp(fov, minFov, maxFov); Camera.main.fieldOfView = fov; if(Input.GetMouseButt
3、on(2)){ float h=hspeed*Input.GetAxis("Mouse X"); float v=vspeed*Input.GetAxis("Mouse Y"); Vector3 rt=new Vector3(v,h,0); transform.RotateAround(target.position,rt,Time.deltaTime*100); } } } Windows using UnityEngine; using System.Collections; public class
4、chuangkou : MonoBehaviour { public Rect windowDialog=new Rect(20,20,150,100); private bool isOnDraw=true; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnGUI(){ if(isOnDraw){ windowDialog=GUI.Window(0,w
5、indowDialog,doMyWindow,"这是一个可拖动的窗口"); } } void doMyWindow(int windowId){ if(GUI.Button(new Rect(10, 20, 100, 20), "关闭窗口")){ isOnDraw=false; } } } Clone using UnityEngine; using System.Collections; public class clone : MonoBehaviour { public Transf
6、orm obj; Vector3 screenPosition; Vector3 mousePositionOnScreen; Vector3 mousePositionInWorld; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { screenPosition=Camera.main.W
7、orldToScreenPoint(obj.position); mousePositionOnScreen=Input.mousePosition; mousePositionOnScreen.z=screenPosition.z; mousePositionInWorld =Camera.main.ScreenToWorldPoint(mousePositionOnScreen); //Camera.main.ScreenToWorldPoint(Input.mousePosition); //此方法将鼠标点击的屏幕坐标转化为相机坐标,即
8、结果永远为相机的position if (Input .GetMouseButtonDown(0)) { //鼠标点击位置创建对象 Instantiate (obj, mousePositionInWorld , Quaternion.identity); } } } } Create using UnityEngine; using System.Collections; public class create : MonoBehaviour { int num=0; public
9、 Texture tex; // Use this for initialization void Start () { GameObject .Find ("sphere/cube"); } // Update is called once per frame void Update () { } void OnGUI(){ if (GUI.Button (new Rect (10,10,80,30),"cube")) { GameObject obj=GameObject.CreatePrimitive (Primiti
10、veType .Cube );
num ++;
obj.name ="URObj"+num ;
obj .transform .renderer .material .mainTexture =tex;
obj.AddComponent
11、ng"); } } 天空 using UnityEngine; using System.Collections; public class move : MonoBehaviour { public Transform diqiu; public Transform taiyang; public Transform yueliang; public Transform shui; public Transform jin; public Transform huo; public Transform mu; public T
12、ransform tu; public Transform tian; public Transform hai; // Use this for initialization void Start () { taiyang = GameObject .Find ("taiyang") .transform; diqiu = GameObject .Find ("diqiu") .transform; yueliang = GameObject .Find ("yueliang") .transform; shui = GameObject .Find
13、"shui") .transform; jin = GameObject .Find ("jin") .transform; huo = GameObject .Find ("huo") .transform; mu = GameObject .Find ("mu") .transform; tu = GameObject .Find ("tu") .transform; tian = GameObject .Find ("tian") .transform; hai = GameObject .Find ("hai") .transform; }
14、 // Update is called once per frame void Update () { diqiu.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 60); diqiu.RotateAround (diqiu.position, Vector3.up, Time .deltaTime * 60); taiyang.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 50); yueliang.
15、RotateAround (diqiu.position, Vector3.up, Time .deltaTime * 30); yueliang.RotateAround (yueliang.position, Vector3.up, Time .deltaTime * 10); shui.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 100); shui.RotateAround (shui.position, Vector3.up, Time .deltaTime * 30); jin.
16、RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 80); huo.RotateAround (huo.position, Vector3.up, Time .deltaTime * 50); huo.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 20); mu.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 15); mu.RotateArou
17、nd (mu.position, Vector3.up, Time .deltaTime * 15); tu.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 10); tian.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 8); tian.RotateAround (tian.position, Vector3.up, Time .deltaTime * 8); hai.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 5); hai.RotateAround (hai.position, Vector3.up, Time .deltaTime * 5); } }






