一 探照灯效果
1、创建一个Plane和一个Cube
2、创建一个点光源放在Cube上方
3、为点光源创建一个脚本,完成探照灯效果
Vector3.Lerp 插值
static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3
两个向量之间的线性插值
public Vector3 newPos;
public float smooth = 3;
void Start () {
newPos = transform.position;
}
void Update () {
if (Input.GetKeyDown(KeyCode.Q)) {
newPos = new Vector3(-3, -3, -6);
}
if (Input.GetKeyDown(KeyCode.E)) {
newPos = new Vector3(3, -3, -6);
}
transform.position = Vector3.Lerp(transform.position,newPos,smooth*Time.deltaTime);
}
二 相机跟随
public Transform player;
public float smooth = 3;
void Update () {
Vector3 pos = player.position + new Vector3(0,20,-20);
transform.position =
Vector3.Lerp(transform.position,pos,smooth*Time.deltaTime);
}
射线、碰撞检测、自动寻径、调用Animation动画
public class Player : MonoBehaviour {
private NavMeshAgent agent;
public GameObject girl;
bool gal = false;
void Start () {
agent=GetComponent<NavMeshAgent>();
}
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Input.GetMouseButtonDown(0)&&Physics.Raycast(ray,out hit))
{
agent.destination = hit.point;
}
if (gal)
{
AnmitionShot();
}
else {
if (agent.remainingDistance == 0){
AnmitionIdle();
}
else{
AnmitionRun();
}
}
}
void OnTriggerStay(Collider other){
if (other.CompareTag(“enemy”)){
gal = true;
other.transform.Translate(0,-0.1f*Time.deltaTime,0);
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag(“enemy”))
{
gal = false;
Messages.blood=Messages.blood+10;
}
}
void AnmitionIdle() {
girl.transform.animation.Play(“idle_look”);
}
void AnmitionRun(){
girl.transform.animation.Play(“run”);
}
void AnmitionShot(){
girl.transform.animation.Play(“kneelSingleShot”);
}
}