Unity 3D 第一更
来源:互联网 发布:车机互联软件哪个好 编辑:程序博客网 时间:2024/05/16 02:09
Unity 3D 第一更
这几年手机随着手机方面硬件的不断提升,手机上面的内存,Cpu,都不断的更新,以前的手机游戏已经不能满足手机发烧友的需求,希望在手机上面也能玩到像PC端的3D游戏,于是Unity 3D引擎就这样诞生了,Unity 3D不仅可以开发出手机方面的游戏,还可以对多个平台进行游戏开发,手机端 PC端 XBOX PSP PS4 andorid Iphone 等系统进行开发,所以今天我们就来说一说,Unity 3D 的游戏开发。 首先说下Unity 3D 基础操作。 Layout 布局 相对按钮
void OnGUI(){ //GUILayout.Width 布局宽度 //GUILayout.Height 布局高度 //GUILayout.MinHeight 最小布局高度 //GUILayout.MinWidth 最小布局宽度 //GUILayout.MaxHeight 最大布局高度 //GUILayout.MaxWidth 最大布局宽度 //GUILayout.ExpandHeight 设置布局整体高度 //GUILayout.ExpandWidth 设置布局整体宽度 // GUILayout.BeginArea(new Rect(100,100,Screen.width,Screen.height)); GUILayout.Button("设置布局按钮宽度为300,高度为30",GUILayout.Height(30),GUILayout.Width(300)); GUILayout.Button("设置最小布局按钮宽度为100,最小高度为20", GUILayout.MinWidth(100), GUILayout.MinHeight(20)); GUILayout.Button("设置最大布局按钮宽度为400,最大高度为40", GUILayout.MinWidth(100),GUILayout.MaxWidth(400), GUILayout.MaxHeight(40)); GUILayout.Button("设置宽度不等于最宽按钮", GUILayout.ExpandWidth(false)); GUILayout.Button("设置宽度为最宽按钮", GUILayout.ExpandWidth(true)); //GUILayout.EndArea();}
Unity 对数字的随机
void Update () { print (Random.Range (0,1)); print (Random.Range (0.0f,1.0f)); }
Unity 实现图片帧动画的脚本
int noFrame = 0; int countFrame = 0; float time = 0; public string path; public int fps = 0; object [] all; // Use this for initialization void Start () { all=Resources.LoadAll(path); countFrame = all.Length; } // Update is called once per frame void Update () { if (all != null) { transform.GetComponent<Renderer>().material.mainTexture = (Texture)all[noFrame]; time += Time.deltaTime; if (time >= 1.0 / fps) { noFrame++; time = 0; } if (noFrame >= countFrame) { noFrame = 0; } } }这里要注意的是在工程里面文件夹起名字的注意事项,文件夹的名称必须是Resources
Unity 中实现Windows窗口
void OnGUI() { //if(Input.GetMouseButton()) GUI.Window(0,new Rect(0,0,100,100),mywindow,"是否接收任务"); } void mywindow(int winid) { GUI.Label(new Rect(13,30,100,100),"撒大大"); } // Update is called once per frame void Update () { print("12312313"); }
Unity 通过按钮读取图片
// Use this for initialization void Start () { } Texture simple; Object [] All; void OnGUI() { if(GUILayout.Button("读取一张图片")) { simple = (Texture)Resources.Load("back"); } if (GUILayout.Button("读取一张图片")) { All = Resources.LoadAll("windmill"); } if(simple!=null) { GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),simple, ScaleMode.StretchToFill,false,0); } if (All!=null) { for (int i =0;i<All.Length ;i++ ) { GUI.DrawTexture(new Rect(i*64, 0, 64,64), (Texture)All[i], ScaleMode.StretchToFill, true, 0); } } } // Update is called once per frame void Update () { }
Unity 插值角度和固定角度
void OnGUI() { if(GUILayout.Button ("旋转固定角度")) { gameObject.transform.rotation = Quaternion.Euler (0,50,0); } if(GUILayout.Button ("旋转插值角度")) { rotate=true; } } bool rotate=false; // Update is called once per frame void Update () { if(rotate) { gameObject.transform.rotation = Quaternion.Slerp (gameObject.transform.rotation,Quaternion.Euler (0,50,0),Time.fixedDeltaTime); } }
Unity 窗口添加文字
int textureWidth; int textureHeight; int ScreenWidth; int ScreenHeight; public Texture texture; string str; // Use this for initialization void Start () { textureWidth=texture.width; textureHeight = texture.height; ScreenWidth=Screen.width; ScreenHeight=Screen.height; str = "第一个Untiy项目"; } void OnGUI() { GUI.Label(new Rect(10,10,330,20), str); GUI.Label(new Rect(10, 30, 330, 120), "当前屏幕宽"+ScreenWidth); GUI.Label(new Rect(10, 50, 330, 20), "当前屏幕高" + ScreenHeight); GUI.Label(new Rect(10, 70, textureWidth, textureHeight), texture); } // Update is called once per frame void Update () { }
在窗口中添加各种按钮
public Texture2D buttonTexture; string strMes; int frameCount; // Use this for initialization void Start () { strMes = "请您点击按钮"; } // Update is called once per frame void OnGUI() { if(GUI.Button(new Rect(10,50,buttonTexture.width,buttonTexture.height),buttonTexture)) { strMes = "您点击了图片按钮"; } GUI.color = Color.green; GUI.backgroundColor = Color.red; if (GUI.Button(new Rect(10, 200, 100,50), "文字按钮")) { strMes = "您点击了文字按钮"; } if(GUI.RepeatButton(new Rect(40,10,120,30),"按钮按下中")) { strMes = "您按下该按钮已经按下的时间为:"+frameCount+""; frameCount++; } GUI.Label(new Rect(10, 10, Screen.width, 30), strMes); } // Update is called once per frame void Update () { }
Unity 窗口分割区域
public Texture t1; public Texture t2; // Use this for initialization void Start() { } void OnGUI() { GUI.BeginGroup(new Rect(0, 0, 600, 600)); GUI.Label(new Rect(300, 390, 100, 100), "啦啦啦啦"); GUI.Label(new Rect(0,0,50,20),"1231asdasdas"); GUI.DrawTexture(new Rect(100,100,150,150),t1); GUI.EndGroup(); GUI.BeginGroup(new Rect(30,30, 600, 600)); GUI.Label(new Rect(300, 390, 100, 100), "啦啦啦啦"); GUI.Label(new Rect(0, 0, 50, 20), "1231asdasdas"); GUI.DrawTexture(new Rect(100, 100, 150, 150), t1); GUI.EndGroup(); } // Update is called once per frame void Update() { //gameObject.GetComponent<Light>().enabled=; //GameObject.fin //提示:射线 //将森林里所有的火把的光默认关掉, //先播放背景音乐(恐怖点的),点击NPC以后,,NPC说话,出现接收任务框,接收任务了以后所有火把点亮 //任务的内容是 拾取10个上古神物,神物的旁边都会有魔法照射 ,有火把的地方就有神物的可能性 }
0 0
- Unity 3D 第一更
- Unity 3D第二更
- Unity 3D 第三更
- Unity 3D之第一个游戏
- Unity 3D之第一个游戏
- Unity 4.x 2D游戏开发基础教程大学霸第一更
- Unity 3d Shader实践 —— 第一个Shader
- Unity 3D
- unity 3d 注意事项
- Unity 3d 摄像头
- Unity 3D 使用
- Unity 3D--PlayerPrefs
- Unity 3d
- Unity 3D俄罗斯方块
- unity 3d 多开
- UNITY 3D笔记
- Unity 3D接触
- unity 3d
- poj 2912 Rochambeau(带权并查集)
- iOS开发 Undefined symbols for architecture i386: _OBJC_CLASS_$_XXX" referenced from: error
- JS性能之runtime
- jquery学习总结(超级详细)
- spring mvc上传下载
- Unity 3D 第一更
- android4.4以上 webview加在图片的缩放问题
- Ubuntu下查看glibc版本
- Python操作Redis之key的查看与删除
- 全球10个最火的初创企业生态系统
- 链表库测试程序
- Linux Make 命令详解
- 华为2016校园招聘上机笔试题2:简单错误记录(并前面错误发现修改1)
- IntentService 的使用