主要内容:
1.碰撞\触发检测
2.场景灯光烘焙
3.粒子火特效
4.灯光动画Animation
5.动画状态机 Animator Controller
6.导航网格Navigation
7.导航组件Nav Mesh Agent
8.射线检测
//主要代码为碰撞检测与射线检测
1.碰撞\触发检测
//碰撞检测
private void OnCollisionEnter(Collision other) {//碰撞物体
print ("!!123!!"+other.collider.name);
}
private void OnCollisionExit(Collision other) {//离开物体
print ("!!456!!"+other.collider.name);
}
private void OnCollisionStay(Collision other) {//每帧调用,与XX碰撞中
print ("!!789!!"+other.collider.name);
}
//触发检测
private void OnTriggerEnter(Collider other) {//触发物体
print ("!!T123!!"+other.name);
}
2.场景灯光烘焙
要烘焙场景设置为静态,在window窗口找到lighting点击build
灯光Baking设置为mixed[混合模式]
3.粒子火特效
Particle System组件
贴图动画,Renderer
动画分割,Texture Sheet Animation
4.灯光动画Animation
Animation Ctrl+6
5.动画状态机 Animator
Animator Controller 组件
6.导航网格Navigation
地面与物体设置为Navigation静态,Bake渲染制作,
物体Navigation Area 可设置为Not Walkable(不可到达)
7.导航组件Nav Mesh Agent
为圆柱体碰撞框。。。
8.射线检测
void Update () {
if(Input.GetMouseButtonDown(0)){//在用户按下鼠标按钮时返回true。
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//射线发射(当前鼠标在像素坐标中的位置。(只读))
RaycastHit hit;//保存碰撞信息用
if(Physics.Raycast(ray,out hit)){//检测射线碰撞
print(hit.point); //在世界空间中射线撞击对撞机的撞击点
agent.SetDestination(hit.point);//前往目标位置
}
}
amn.SetFloat("speet",agent.velocity.magnitude);
//动画设置值("speet",速度.大小,返回这个向量的长度(只读))
//NavMeshAgent.velocity 速度
}