Unity3D最近所学知识实践
2015-01-21 22:10
204 查看
一 探照灯效果
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”);
}
}
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”);
}
}
相关文章推荐
- 最近所学网络知识的一个总结
- wireshark与最近所学知识的感想
- 最近一直在学JS方面的知识,想要把自己所学与大家分享
- 高效程序员的45个习惯:敏捷开发修炼之道(融知识、哲理、实践于一体的奇书)
- 解析敏捷软件开发知识体系 分享国外敏捷转型实践案例
- 【Unity3D基础知识点】——射线
- 网络实践类知识笔记
- Unity3d知识体系思维导图
- 使用Unity3D的50个技巧:Unity3D最佳实践
- Unity3D实践系列10, Canvas画布的创建和使用
- Unity3D光照贴图烘焙知识详解
- Android实践:《简易照相机》的详细实现步骤及知识梳理
- 程序员七宗罪 误区一:注重理论,轻视实践:学习新知识钱想把这方面的理论全部掌握后再去实践。========> 大错特错 解决方法:在了解理论之后,就立即去实践,实践驱动理论的学习,这样掌握理论才更加扎
- 最近读了Robert C. Martin的《敏捷软件开发 原则、模式与实践》
- 最近学到的一些知识
- 【转】unity3d所要知道的基础知识体系大纲
- 最近需要总结的一些知识
- 9.18所学的知识
- 9-Shell的逻辑操作符知识介绍-实践及企业案例脚本剖析
- 最近打算好好整理整理知识,这里列出可参考的博客列表