zoukankan      html  css  js  c++  java
  • unity8个入门代码

    01,基本碰撞检测代码

    function OnCollisionEnter(theCollision:Collision){

      if(theCollision.gameObject.name=="Floor"){

          Debug.Log("Hit the floor");

      } else if(theCollision.gameObject.name=="Wall"){

        Debug.Log("Hit the Wall);

      }

    }

    02,检测输入

    function Update(){

      if( Input.GetButtonUp("Jump"){

       Debug.Log("We Have HIt The Space Bar");

      }

    }

    03,销毁对象

    function Update(){

      Destroy(game.Find("Box"),3); 

    }

    04,实例创建对象

    GameObject g=Instantiate(PREFAB,Pos,transform.rotation);

    05,简易定时器

    var myTimer: float =5.0f;

    function Update(){

      if(myTimer>0)

      myTimer-=Time.deltaTime;}

      if(myTimer<=0)

      Debug.log("Game  End");}

    }

    06,物体移动

    var speed:float =5.0f;

    function Update(){

      transform.Translate(Vector3(0,0,speed)*Time.deltaTime);//Time.deltaTime:每秒耗时

    }

    07,刚体向目标处移动

    var power:float =500.0f;

    function Update(){

      rigibody.AddForce(Vector3(0,0,power);//Time.deltaTime:每秒耗时

    }

    08,碰撞然后转到下一个场景

    function OnCollisionEnter(theCollision:Collision){

      if(theCollision.gameObject.name=="Floor"){

          Application.LoadLevel("name");//参数亦可以是int型的

      } 

    }

  • 相关阅读:
    Class attributes
    Card objects
    Exercises
    Type-base dispatch
    Operator overloading
    The str method
    loadrunner协议开发
    nmon分析与详解
    如何判断CPU、内存、磁盘的性能瓶颈?
    用友NC客户端地址
  • 原文地址:https://www.cnblogs.com/allyh/p/9240244.html
Copyright © 2011-2022 走看看