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

  • 相关阅读:
    python视频教程大全(转载)
    数据挖掘十大经典算法(转载)
    等值线算法(转载)
    主成分分析PCA(转载)
    K-Means 算法(转载)
    面试常见问题小结
    二叉树的深度和宽度
    二叉树最大路径和-Binary Tree Maximum Path Sum
    C++中单例模式
    OC对象的动态和静态构造区别
  • 原文地址:https://www.cnblogs.com/softimagewht/p/1900872.html
Copyright © 2011-2022 走看看