unity3d

Unity 常用脚本:OnGUI(一)GUI(借鉴大神,仅作为笔记用)

百般思念 提交于 2021-01-07 08:34:56
OnGUI是Unity中通过代码驱动的GUI系统 主要用来创建调试工具、创建自定义属性面板、创建新的Editor窗口和工具达到扩展编辑器效果。 OnGUI不建议使用在项目UI中。 布局上,坐标系原点在屏幕左上角。 https://docs.unity3d.com/Manual/gui-Controls.html Box矩形框 using System.Collections; using System.Collections.Generic; using UnityEngine; public class TestOnGUI : MonoBehaviour { void OnGUI() { GUI.Box(new Rect(10,10,100,90),"看这里!"); } } Button按钮 using System.Collections; using System.Collections.Generic; using UnityEngine; public class TestOnGUI : MonoBehaviour { void OnGUI() { if (GUI.Button(new Rect(20, 40, 80, 20), "点这里!")) { Debug.Log("OK"); } } } Label标签 标签是非交互式的。只供展览。无法单击或以其他方式移动

Unity中的各种坐标系及相互转化(借鉴大神,仅作为笔记用)

痴心易碎 提交于 2021-01-07 08:10:30
Unity作为一个3D开发引擎,他的各系坐标系错综复杂,学过矩阵的朋友可能还绕得开,没有学会的一不小心就掉进坐标坑里面了,其实各系坐标的区别在于所建立的坐标系参照不同,下面先了解下各大坐标吧,我尽量说的通俗点。 1.坐标系 1.世界坐标系:以世界原点为坐标原点建立的三维坐标系,凡是在Unity的游戏对象均有自己的世界坐标系,且获取坐标的方法很简单(transform.position),这类似与现实世界我们常说的经纬度,常用来做定义位置,方向的标准。 2.本地坐标(自身坐标):以自身为原点而建立的三维坐标系,该坐标为局部坐标,与世界坐标系一样,凡是Unity的游戏对象均有自己的自身坐标,获取坐标的方法也很简单(transform.localposition),常用来用于定义自身方向,初始局部位置来用,例如背包当更换物品是其实实在更换UI,而更换UI实则更换UI父对象,然后让transform.localposition=Vector3.zero让他等于其父对象的位置。 3.屏幕坐标:以屏幕左下角为原点建立的一个二维坐标系.以屏幕的左下角为(0,0),右上角为(Screen.width,Screen.height),这个坐标坑最多,也是我们经常最绕的一个坐标,这里就详解下,首先屏幕要知道是相对屏幕。举个例子,现实的投影仪大家很清楚,我们在天花板顶上放一个投影仪

Unity游戏设计与实现 南梦宫一线程序员的开发实例

爱⌒轻易说出口 提交于 2021-01-07 07:54:12
图灵程序设计丛书 Unity游戏设计与实现:南梦宫一线程序员的开发实例(修订版) 加藤政树 (作者) c# 游戏 unity <内容提要> 本书的作者是日本知名游戏公司万代南梦宫的资深开发人员,书中通过10个不同类型的游戏实例,展示了真正的游戏设计和实现过程。本书的重点不在于讲解Unity的各种功能细节,而在于介绍核心玩法的设计和实现思路。每个实例都从一个idea开始,不断丰富,进而自然而然地推出各种概念,引导读者思考必要的数据结构和编程方法。掌握了这些思路,即便换成另外一种引擎,也可以轻松地开发出同类型的游戏。 本书特色 游戏开发者奥斯卡CEDEC AWARDS 2013最优秀著作奖,旧版豆瓣9.3分好评图书,基于Unity5全面升级! ★ 10个典型的开发实例,覆盖基本游戏类型  怪物——点击动作游戏  迷你拼图——拼图游戏  地牢吞噬者——吃豆游戏  In the Dark Water——3D声音探索游戏  摇滚女孩——节奏游戏  噬星者——全方位滚动射击游戏  吃月亮——消除动作解谜游戏  猫跳纸窗——跳跃动作游戏  村子里的传说——角色扮演游戏  迷踪赛道——驾驶游戏 ★ 南梦宫资深开发者执笔,重点讲解设计思路和实现细节,公开灵感来源 每个实例都从一个idea开始,不断丰富,将玩法规则具体化之后,进而规划各功能模块,引导你思考必要的数据结构和编程方法

IEnumerator yielding to the result of another IEnumerator

半腔热情 提交于 2021-01-07 05:07:18
问题 I have two classes set up in my project. On a button press in the first class I am calling the first IEnumerator on a button press: if(GUI.Button(new Rect(250, 0, 100, 20), "clear")) { StartCoroutine(Foo.test()); } The method being called looks like this (in the other class): public static IEnumerator test() { yield return StartCoroutine(DownloadAndCache()); // do stuff } However, I'm intending this method to only carry out its actions once it gets a return from a second IEnumerator that

MeshRenderer has wrong bounds when rotated

拥有回忆 提交于 2021-01-07 03:26:06
问题 When I try to get the bounds of my models (created in Blender) and show them in Inspector: As you can see the bounds are correct when the objects are not rotated. But when they are (left-most object) bounds start getting totally wrong. Here is a script that shows / gets the bounds: using System.Collections; using System.Collections.Generic; using UnityEngine; public class GetBounds : MonoBehaviour { public MeshRenderer mesh_renderer = null; public bool show_bounds = false; private void

Unity camera flicks across screen, first person

六眼飞鱼酱① 提交于 2021-01-07 01:32:36
问题 Hello I am new to UNITY I have written some code for a first person camera however sometimes when I am looking around it will flick what way the camera is facing. This is my code public float mouseSensitivity = 200f; public Transform playerBody; float yRotation = 0f; // Start is called before the first frame update void Start() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } // Update is called once per frame void Update() { float mouseX = Input.GetAxis("Mouse X") *

Unity camera flicks across screen, first person

偶尔善良 提交于 2021-01-07 01:30:01
问题 Hello I am new to UNITY I have written some code for a first person camera however sometimes when I am looking around it will flick what way the camera is facing. This is my code public float mouseSensitivity = 200f; public Transform playerBody; float yRotation = 0f; // Start is called before the first frame update void Start() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } // Update is called once per frame void Update() { float mouseX = Input.GetAxis("Mouse X") *

Unity2019学习:常用功能--Canvas画布

♀尐吖头ヾ 提交于 2021-01-06 11:54:43
Canvas(画布)游戏对象是其他Unity UI的基础,其他的Unity UI必须是Canvas(画布)游戏对象的下级游戏对象。 当UI内容发生变化的时候,是以画布为单位进行重绘,合理的将内容分配到不同的画布可以提高性能。 Render Mode(渲染模式) Screen Space Overlay(屏幕空间-覆盖) 屏幕空间-覆盖是根据屏幕分辨率进行渲染,不参考场景中的任何游戏对象或者摄像机,渲染之后将其绘制在其他所有内容之上。 Screen Space Camera(屏幕空间-摄像机) 屏幕空间-摄像机是将画布设置为摄像机前方视野中的一个平面。 这种模式下,必须通过Render Camera(渲染摄像机)属性来指定摄像机,且只有在被指定的摄像机中,画布才是可见的。 Plane Distance(平面距离)属性用来指定画布到摄像机的距离,该距离不会影响画布中内容的大小,但是会被距离摄像机更近的其他游戏对象遮挡。如果Plane Distance(平面距离)属性的取值在摄像机Clipping Planes(剪裁平面)属性的取值范围之外,画布仍然是不可见的。 World Space(世界空间) 世界空间这种渲染模式是将画布变成了Unity空间的一个普通游戏对象来处理。世界空间这种渲染模式的画布经常做游戏对象的名称或者说明上,如NPC头顶的名称,血条。 Canvas Group(画布组

How to import an fbx in Unity correctly?

橙三吉。 提交于 2021-01-06 07:23:54
问题 I've modelled an object and exported as fbx. After I import the asset in Unity, some artefacts show up. The artefacts seem to be related to Unity import and not do the fbx file as the model viewed in Windo3d 3d viever seem to have no issues. Thank you a lot! Object in Blender Edit mode Object in Blender Object mode Object in Windows 3d Object in Unity 回答1: It looks like a triangle winding problem. The order of the vertices in a triangle, when combined with their visual orientation, can be

How to import an fbx in Unity correctly?

夙愿已清 提交于 2021-01-06 07:23:43
问题 I've modelled an object and exported as fbx. After I import the asset in Unity, some artefacts show up. The artefacts seem to be related to Unity import and not do the fbx file as the model viewed in Windo3d 3d viever seem to have no issues. Thank you a lot! Object in Blender Edit mode Object in Blender Object mode Object in Windows 3d Object in Unity 回答1: It looks like a triangle winding problem. The order of the vertices in a triangle, when combined with their visual orientation, can be