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型的

      } 

    }

  • 相关阅读:
    numpy学习之矩阵之旅
    HDFS之深入简出(一)
    Hadoop特点
    ThreadLocal的理解
    DBCP连接数据库了解一下
    DBCP连接数据库了解一下
    axaj 的回调
    javaWEB登录ajax传值
    JavaWeb网站后台开发记录手册
    Python--控制循环语句
  • 原文地址:https://www.cnblogs.com/allyh/p/9240244.html
Copyright © 2011-2022 走看看