zoukankan      html  css  js  c++  java
  • 一些有用的函数

    ------------读取外部文本---------------------------

    var MyText: TextAsset;

    function OnGUI () {
    GUI.Label(Rect(10, 10, 500, 500), Text2.text);
    }

    -----------GUI函数 判断鼠标按下-------------

      if((Event.current.type == EventType.mouseDown) && (Event.current.button == 0))
      {
         print("asdasdasd");
      }

    -----------------------跳----------------------------------

    function FixedUpdate ()
    {
     if (Input.GetButtonDown ("Jump"))
     {
      rigidbody.velocity = Vector3(0,5,0);
     }
    }

    -------------------------------------------

    var speed : float = 6.0;
    var jumpSpeed : float = 8.0;
    var gravity : float = 20.0;
    private var moveDirection : Vector3 = Vector3.zero;

    function Update()
    {
     var controller : CharacterController = GetComponent(CharacterController);
     if (controller.isGrounded)
     {
      moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
      Input.GetAxis("Vertical")); //局部坐标
      moveDirection = transform.TransformDirection(moveDirection); //转换成全局坐标
      moveDirection *= speed;//这里把速度给了X和Z轴 Y轴有自己的速度
      if (Input.GetButton ("Jump"))
      {
       moveDirection.y = jumpSpeed;//速度越大越高
      }
     }
     moveDirection.y -= gravity * Time.deltaTime;
     controller.Move(moveDirection * Time.deltaTime);
    }

    ----------------------

    var speed : float = 3.0;
    var rotateSpeed : float = 3.0;
    function Update ()
    {
     var controller : CharacterController = GetComponent(CharacterController);
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
     var forward : Vector3 = transform.TransformDirection(Vector3.forward);
     var curSpeed : float = speed * Input.GetAxis ("Vertical");
     controller.SimpleMove(forward * curSpeed);
    }
    @script RequireComponent(CharacterController)
     ----------------载入一个文件夹所有贴图-----------

    //一个载入的数组变量
    var textures:Object[];

    //创建一个Cube模型
    go = new GameObject.CreatePrimitive(PrimitiveType.Cube);

    //载入这个路径文件夹Texture2D类型的贴图到textures数组中
    textures = Resources.LoadAll("Textures", Texture2D);

    //循环整个文件夹的贴图,然后做某个事情
    for(var k:Texture2D in  textures)
    {
       go.renderer.material.mainTexture =textures[4];
       dosomething();
    }

     ------------角色控制推动刚体-------------

    var pushPower = 2.0;
    var speed : float = 6.0;
    var jumpSpeed : float = 8.0;
    var gravity : float = 20.0;
    private var moveDirection : Vector3 = Vector3.zero;

    function OnControllerColliderHit (hit : ControllerColliderHit)
    {
     var body : Rigidbody = hit.collider.attachedRigidbody;
     if (body == null || body.isKinematic)
     return;
     if (hit.moveDirection.y < -0.3)
     return;
     var pushDir : Vector3 = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
     body.velocity = pushDir * pushPower;
    }

  • 相关阅读:
    linux网络编程之扫盲
    当lov变化时得到lov变化的值
    动态设置OAMessageChoiceBean值
    RSA host key for HOST has changed and you have requested strict checking
    64位整数的编译错误
    CSS让内容水平居中(固定宽度)
    如何计算亮度值
    adb新参数支持Android 2.2安装到SD卡上
    NSDateFormatter formatting
    Win7系统下Safari不能打开网页的解决方法
  • 原文地址:https://www.cnblogs.com/softimagewht/p/1900872.html
Copyright © 2011-2022 走看看