Terrain(地形)
Unity自带各种资源包。
Brush Size 设置笔刷大小,Opacity 设置精度大小,越小越不容易改变地形,适合细微操作。
Height 设置地面高度,只有有一定高度,地面才可以忘下陷。按住Shift。
第三个按钮是平滑操作,消除尖锐部分。
第四个按钮添加地形的贴图材质Textures。
第五个按钮绘画树木,需要添加树木的Prefab。
第六个添加草地Textures。
第七个可以设置地形的大小。
Character Controller(角色控制器)
Slope Limit :设置角色爬坡角度,默认45.90可以爬任何地形。然后设置角色的Collider大小。
脚本控制:首先 声明
private CharacterController characterController;
characterController=GetComponent();
摄像机固定,控制角色转向移动。在角色下创建Camera,设置好角度,点击GameObject的Align With view。
Update()=>
transform.Roate(new Vector3(0,Input.GetAxis(“Horizontal”)*30*Time.deltaTime,0));
characterController.SimpMove(transform.forward*speed*Input.GetAxis(“Vertical”));
角色控制的的转换
Player1 Player2 都使用CharacterController。设置一个标志位。
public bool isGetControl; 禁用其中一个Camera。
if(isGetControl)=>控制角色脚本
共同方法:
public void GetControl=>
isGetControl=true;
camera.setActive=true;
public void LossControl=>
isGetControl=false;
camera.setActive=false;
在其中一个角色脚本里控制转换。
public Player2 player2;
if(Input.GetKeyDown(KeyCode(Space))
=>if(isGetControl)
=>this.LossControl(); player2.GetControl();
else
=>this.GetControl(); palyer2.LossControl();
NPC自动行走
首先设置一个时间标志位 timer=2.0f; 如果时间到,就改变方向和状态。
Update()=>
timer-=Time.deltaTime;
if(timer<=0)=>
if(idel)=>
idle=false;
timer=5.0f;
transform.Roate(new Vector3(0,Random.range(90,-90),0));
walkAnimation;
else=>
idle=ture;
timer=2.0f;
idleAnimation;
if(!idle)=>
transform.SimpMove(transform.forword*speed);
OnGUI
void OnGUI=>
GUI.Lable(new Rect( x,y,length,width),”hello unity”);
bool yes = GUI.Button(new Rect(Screen.width/2,Screen.Length/2,40,20),”YES”);
if(yes)=>Debug.log(“OK”);
各种灯光
平行光(太阳光),点光源(灯泡),锥形光(手电筒),平面光(探照灯)