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;
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.GetMouseButton(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 chuangkou : MonoBehaviour {
public Rect windowDialog=new Rect(20,20,150,100);
private bool isOnDraw=true;
// Use this for initialization
void Start () {
float up }
// Update is called once per frame
void Update () {
}
void OnGUI(){
if(isOnDraw){
windowDialog=GUI.Window(0,windowDialog,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 Transform 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.WorldToScreenPoint(obj.position);
usePosition;
mousePositionOnScreen.z=screenPosition.z;
mousePositionInWorld =Camera.main.ScreenToWorldPoint(mousePositionOnScreen);
//Camera.main.usePosition);
//此方法将鼠标点击的屏幕坐标转化为相机坐标,即结果永远为相机的position
if (Input .GetMouseButtonDown(0)) {
//鼠标点击位置创建对象
Instantiate (obj, mousePositionInWorld , Quaternion.identity);
}
}
}
}
Create
using UnityEngine;
using System.Collections;
public class create : MonoBehaviour {
int num=0;
public 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 (PrimitiveType .Cube );
num ++;
obj.name ="URObj"+num ;
obj .transform .renderer .material .mainTexture =tex;
obj.AddComponent<Rigidbody>();
obj .transform .position =new Vector3 (num*0.5f,num,0);
}
GUI.Button (new Rect (10,40,80,30),"HOME");
Application .LoadLevel ("zongdiaoyong");
}
}
天空
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 Transform 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 ("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;
}
// 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.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.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);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论