zoukankan      html  css  js  c++  java
  • 物体也能正常移动

    if (Input.GetKeyDown(kcode))
    {
    ChangeKeyPressState(kcode, true);
    }
    if (Input.GetKeyUp(kcode))
    {
    ChangeKeyPressState(kcode, false);
    }
    }
    }
    //记录按键的按压状态
    void ChangeKeyPressState(KeyCode keycode, bool isPress)
    {
    switch (keycode)
    {
    case INPUT_UP:
    isUpPress = isPress;
    break;
    case INPUT_DOWN:
    isDownPress = isPress;
    break;
    case INPUT_LEFT:
    isLeftPress = isPress;
    break;
    case INPUT_RIGHT:
    isRightPress = isPress;
    break;
    }
    }
    //确定移动方向
    void CheckMoveDir()
    {
    //确定方向
    if (isUpPress && isLeftPress)
    {
    moveDir = MoveDir.UL;
    }
    else if (isUpPress && isRightPress)
    {
    moveDir = MoveDir.UR;
    }
    else if (isDownPress && isLeftPress)
    {
    moveDir = MoveDir.DL;
    }
    else if (isDownPress && isRightPress)
    {
    moveDir = MoveDir.DR;
    }
    else if (isUpPress)
    {
    moveDir = MoveDir.Up;
    }
    else if (isDownPress)
    {
    moveDir = MoveDir.Down;
    }
    else if (isLeftPress)
    {
    moveDir = MoveDir.Left;
    }
    else if (isRightPress)
    {
    moveDir = MoveDir.Right;
    }
    else
    {
    moveDir = MoveDir.None;
    }
    }
    //检测是否可以移动
    void CheckMove()
    {
    //某些情况下可能禁止移动 例如暂停 播放GC等
    if (canMove && moveDir != MoveDir.None)
    {
    PlayerMove(target, speed);
    }
    }
    //移动
    void PlayerMove(Transform target, float speed)
    {
    move_dis = speed * Time.deltaTime * GetSpeedDir();
    target.position += move_dis;
    }
    //速度向量
    Vector3 GetSpeedDir(http://www.my516.com/heimitao/)
    {
    switch (moveDir)
    {
    case MoveDir.Up:
    move_speed_dir = MOVE_UP;
    break;
    case MoveDir.Down:
    move_speed_dir = -MOVE_UP;
    break;
    case MoveDir.Left:
    move_speed_dir = -MOVE_RIGHT;
    break;
    case MoveDir.Right:
    move_speed_dir = MOVE_RIGHT;
    break;
    case MoveDir.UL:
    move_speed_dir = MOVE_UP - MOVE_RIGHT;
    break;
    case MoveDir.UR:
    move_speed_dir = MOVE_UP + MOVE_RIGHT;
    break;
    case MoveDir.DL:
    move_speed_dir = -MOVE_UP - MOVE_RIGHT;
    break;
    case MoveDir.DR:
    move_speed_dir = -MOVE_UP + MOVE_RIGHT;
    break;
    }
    return move_speed_dir.normalized;
    }

    }
    --------------------- 

  • 相关阅读:
    717. 1比特与2比特字符
    697. 数组的度
    674. 最长连续递增序列
    665. 非递减数列
    661. 图片平滑器
    643. 子数组最大平均数 I
    plink计算两个SNP位点的连锁不平衡值(LD)
    GWAS群体分层校正,该选用多少个PCA
    PyCharm的安装和应用
    GWAS后续分析:多基因风险评分(Polygenic Risk Score)的计算
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11277819.html
Copyright © 2011-2022 走看看