随笔分类 -  Unity3d

Quaternion 四元数运算
摘要:transform.rotation = Quaternion.Euler(new Vector3(45,a++,0));设置transform的旋转量为绕x轴旋转45度,y轴旋转量累加(y轴这时仍是世界坐标的旋转轴)transform.rotation = Quaternion.Euler(new Vector3(45,0,0)) * Quaternion.Euler(new Vector3(0,a++,0));同样为设置旋转量,但是此句是在x轴旋转45度后再对物体按照其自身的y轴旋转量累加(y轴这时为物体自身的旋转轴)两者效果不一致 阅读全文
posted @ 2012-12-28 10:54 雨季 阅读(1557) 评论(0) 推荐(0)
unity3d中自带的GUI实现下拉列表框
摘要:usingUnityEngine;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem;publicclassComboBox:MonoBehaviour{privateDictionary<object,object>dataSource;privateobjectcurrentValue;privateobjectcurrentDisplayText;privateintcurrentIndex;privateGUISkinskin;privateRectrect 阅读全文
posted @ 2012-10-09 14:29 雨季 阅读(16886) 评论(2) 推荐(0)
使用向量插值调整ScrollView中鼠标滚动灵敏度
摘要:scrollPosition=Vector2.Lerp(scrollPosition,GUI.BeginScrollView(rectList,scrollPosition,rectListView,false,true),0.5f);BeginScrollView返回值与原始值做差值运算,这里参数为0.5f其实就是取两者的平均数。算个小技巧吧,主要问题还是向量的运算 阅读全文
posted @ 2012-10-09 14:27 雨季 阅读(534) 评论(0) 推荐(0)
Vector3函数理解-计算两向量之间的角度
摘要:1.已知两个向量dirA,dirB。Vector3 dirA = new Vector3(-1,1,0);Vector3 dirB = new Vector3(-1,1,1);2.使向量处于同一个平面,这里平面为XZdirA = dirA - Vector3.Project(dirA,Vecotr3.up);dirB = dirB - Vector3.Project(dirB,Vecotr3.up);注:Vector3.Project计算向量在指定轴上的投影,向量本身减去此投影向量就为在平面上的向量3.计算角度float angle = Vector3.Angle(dirA,dirB);4.计 阅读全文
posted @ 2012-09-03 18:18 雨季 阅读(20316) 评论(0) 推荐(0)
物体朝向控制
摘要:voidUpdate(){if(inRotation){Quaternionrotation=Quaternion.LookRotation(target.position-this.transform.position);floatt=Mathf.Min(Time.deltaTime*2,1);rotation=Quaternion.Lerp(transform.rotation,rotation,t);this.transform.rotation=rotation;if(t==1){inRotation=false;}}}voidOnGUI(){if(GUI.Button(newRect 阅读全文
posted @ 2012-07-19 11:10 雨季 阅读(570) 评论(0) 推荐(0)
鼠标控制人物控制器移动
摘要:usingUnityEngine;usingSystem.Collections;publicclassPlayerMoveToTarget:MonoBehaviour{publicCharacterController[]players;publicVector3[]targetPosition;privateintrotationSpeed=5;privatefloatspeed=0.05f;publicCameracamera;voidStart(){targetPosition=newVector3[players.Length];for(inti=0;i<players.Len 阅读全文
posted @ 2012-07-17 10:52 雨季 阅读(660) 评论(0) 推荐(0)
Mesh网格基础知识
摘要:下面是摘自网上的一篇教程,写得不错//通过object对象名face得到网格渲染器对象MeshFiltermeshFilter=(MeshFilter)GameObject.Find("face").GetComponent(typeof(MeshFilter));//通过渲染器对象得到网格对象Meshmesh=meshFilter.mesh;//API中写的不是提清楚,我详细的在说一遍//设置顶点,这个属性非常重要//三个点确定一个面,所以Vector3数组的数量一定是3个倍数//遵循顺时针三点确定一面//这里的数量为6也就是我创建了2个三角面//依次填写3D坐标点mes 阅读全文
posted @ 2012-06-26 10:22 雨季 阅读(9071) 评论(0) 推荐(0)
摄像机朝向指定物体
摘要:脚本绑定到摄像机,x是指摄像机视角左右旋转角度,y是指摄像机视角上下旋转角度,target为目标物体。initDis为初始化摄像机与目标物体的距离。首先设置摄像机旋转角度,这里Euler(y, x, 0),意义为绕x轴旋转y角度,三维空间中绕x轴旋转即为上下旋转,绕y轴旋转x角度,三维空间中绕y轴旋转即为左右旋转。transform.rotation = Quaternion.Euler(y, x, 0);Vector3(0.0, 0.0, -initDis)意义为z轴方向距离原点(0,0,0)为initDis,Quaternion * Vector3意义为向量Vector3绕原点旋转Quat 阅读全文
posted @ 2012-06-26 09:54 雨季 阅读(735) 评论(0) 推荐(0)