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); } }
// 移动数据逻辑和动画 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(); }
// 注册一个可减速物件 public void registerGO(TimeScaledGO tgo) { tgoList.Add(tgo); // 设置除了Ghost之外的慢动作 Ghost g = tgo.GetComponent <Ghost>(); if (g == null) { tgo.isAffectedByTimeScale = isAllSlowDown; } }
// 只减速一个物件 public void slowDownOne(TimeScaledGO tgo) { slowDownTime(); foreach (var one in tgoList) { if (one != tgo) { one.isAffectedByTimeScale = false; } else { one.isAffectedByTimeScale = true; } } }
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; }
// 减速一个物件除外的所有物件 public void slowDownAllButOne(TimeScaledGO tgo = null) { slowDownTime(); foreach (var one in tgoList) { if (tgo && one == tgo) { one.isAffectedByTimeScale = false; } else { one.isAffectedByTimeScale = true; } } isAllSlowDown = true; }
// 反注册一个可减速物件 public void unregisterGO(TimeScaledGO tgo) { tgoList.Remove(tgo); }