Unity3D最近所学知识实践

一  探照灯效果


   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”);
      }

  }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值