Exemplo n.º 1
0
    // 移动数据逻辑和动画
    private void walk()
    {
        // 获取现在移动速度, 如果有速度, 播放移动动画, 如果没有速度, 不播放移动动画
        float nowSpeed = getNowSpeed();

        if (nowSpeed > 0)
        {
            anim.SetBool("Walk_Anim", true);
        }
        else
        {
            anim.SetBool("Walk_Anim", false);
        }

        // 根据时间控制模块来获取控制移动距离的时间参数
        float        deltaTime;
        TimeScaledGO tgo = GetComponent <TimeScaledGO>();

        if (tgo != null)
        {
            deltaTime = tgo.getDeltaTime();
        }
        else
        {
            deltaTime = Time.deltaTime;
        }

        // 实际移动和转向
        transform.position += transform.forward * nowSpeed * deltaTime;
        transform.rotation  = getRotation();
    }
Exemplo n.º 2
0
    public void Move(float v, float h)
    {
        TimeScaledGO tgo = GetComponent <TimeScaledGO>();
        float        deltaTime;
        float        timeScale;

        if (tgo != null)
        {
            deltaTime = tgo.getDeltaTime();
            timeScale = tgo.getTimeScale();
        }
        else
        {
            deltaTime = Time.deltaTime;
            timeScale = Time.timeScale;
        }
        robotAnimator.SetFloat("Forward", h * timeScale);
        if (h != 0 && robotMode == 1)
        {
            robotTransform.position += h * transform.forward * deltaTime * tankSpeed;
            robotTransform.position += v * -transform.right * deltaTime * tankSpeed * 0.2f;
        }
        else if (h != 0 && robotMode == 2)
        {
            robotRigidBody.AddForce(h * transform.forward * Time.deltaTime * planeSpeed);
        }
    }
Exemplo n.º 3
0
    protected virtual void Update()
    {
        // 根据时间管理组件来计算子弹速度.
        float        deltaTime;
        TimeScaledGO tgo = GetComponent <TimeScaledGO>();

        if (tgo != null)
        {
            deltaTime = tgo.getDeltaTime();
        }
        else
        {
            deltaTime = Time.deltaTime;
        }
        transform.position += deltaTime * bulletSpeed * transform.forward;
    }