模型的获取途径在(1)里讲过了,导入及放置自己试试,很容易会。
网上看来的一个经典例子,太阳地球月亮的旋转,来进行模型光照和角色移动的实践。
创建3个基本球体,太阳稍大,地球次之。然后随意改改颜色,使之能够区分。
给太阳加一个点光源,,光强设置为8
,颜色改为亮黄。
三个天体的自转不管了,公转代码写一下。
地球的:
using UnityEngine;
using System.Collections;
public class earthRotate : MonoBehaviour
{
private GameObject sun;
// Use this for initialization
void Start()
{
sun = GameObject.Find("sun");
}
// Update is called once per frame
void Update()
{
transform.RotateAround(sun.transform.position,Vector3.up, 3f);
}
}
月球的:
using UnityEngine;
using System.Collections;
public class moonRotate : MonoBehaviour {
private GameObject earth;
private GameObject sun;
// Use this for initialization
void Start () {
earth = GameObject.Find("earth");
sun = GameObject.Find("sun");
}
// Update is called once per frame
void Update () {
//Debug.Log(earth.transform.position);
transform.RotateAround(sun.transform.position, Vector3.up, 3f);
transform.RotateAround(earth.transform.position,Vector3.up,2f);
}
}
运行后可以很好的实现旋转。--over
场景的切换:需要先将所有相关场景放置到build setting中,即build一下。然后可以通过下面代码实现切换
Application.loadLevel("next scene");
--over
场景的初始化:
1.场景添加雾的效果,在unity5之前是在render setting中点勾选Fog添加雾。unity 5.1添加雾是在window-》Lighting-》scene下勾选。
2.给摄像头一个缓慢拉近效果,然后添加脚本MoveCamera.cs
using UnityEngine;
using System.Collections;
public class MovieCamera : MonoBehaviour {
public float speed = 10;
private float endZ = -10;
void Start () {
}
void Update () {
if (transform.position.z < endZ) {//还没有达到目标位置,需要移动
transform.Translate( Vector3.forward*speed*Time.deltaTime);
}
}
}
3.修改鼠标样式,在File-》build Setting-》Player setting中修改Default Cursor的贴图。
4.在其他地方看到的登陆界面缓慢变透明效果,就是在初始化NGUI界面后,添加一个NGUI->Tween->Alpha的一个动画,在属性面板调整,让渐变由1变为0,delay time适当调整。就能实现登陆界面的渐变消失效果,蛮炫的。
5.人物头像的制作,新建一个camera放到角色下,然后对准脸部,设定camera的Layer只对角色,新建一个render texture拖拽到camera的target texture。然后修改下camera的背景色就可以。此时这个texture就是人物头像的simple texture,小地图同理,不同处为设置相机为立方体型,然后NPC或者怪物的layer取消选择,在其头上放置quad设置图标予以区别,勾选图标的layer。地图的放大缩小可以控制摄像机的size。