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

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

  • 相关阅读:
    HDU 2955 Robberies
    CodeForces 429B Working out DP
    Lweb and String 超级大水题
    A water problem 大数取余。
    Danganronpa 水题。
    HDU 2018 DP
    Git分支管理
    linux相关操作命令
    项目部署相关命令(pm2)
    ubantu16.04安装sougou输入法
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11277819.html
Copyright © 2011-2022 走看看