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

  • 相关阅读:
    Windows API 之 Windows Service
    揭开Socket编程的面纱 (一)
    开发中“错误: 意外地调用了方法或属性访问。” 和 第一行错误 的IE 两个问题( JQ 进行转义字符 , 分页JS 调用 时参数问题。)
    结合MSDN理解windows service 服务安装的三个类。
    VFW基础知识(一些定义性质的。从CSDN中得到的。)
    初次接触WIN FORM,深入事件、委托、方法 ,深入看不到的C#探索。
    C#: +(特性 ) + Attitude C#(类)前面或者(方法)前面 (中括号)定义
    VFW系列教程经典
    依赖注入
    Windows Service:SC 和 InstallUtil 区别
  • 原文地址:https://www.cnblogs.com/softimagewht/p/1900872.html
Copyright © 2011-2022 走看看