收藏 分销(赏)

UNITY-c#程序.docx

上传人:仙人****88 文档编号:11959286 上传时间:2025-08-22 格式:DOCX 页数:4 大小:15.27KB 下载积分:10 金币
下载 相关 举报
UNITY-c#程序.docx_第1页
第1页 / 共4页
UNITY-c#程序.docx_第2页
第2页 / 共4页


点击查看更多>>
资源描述
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 () { } // 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); mousePositionOnScreen=Input.mousePosition; mousePositionOnScreen.z=screenPosition.z; mousePositionInWorld =Camera.main.ScreenToWorldPoint(mousePositionOnScreen); //Camera.main.ScreenToWorldPoint(Input.mousePosition); //此方法将鼠标点击的屏幕坐标转化为相机坐标,即结果永远为相机的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); mu.RotateAround (taiyang.position, Vector3.up, Time .deltaTime * 15); mu.RotateAround (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); } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服