void HandleMouse()
{
if(Input.GetMouseButton(0))
{
if(isTouching)
{
HandleDragging();
}
}
else
{
isTouching = false;
ResetKnob();
}
}
void HandleTouches()
{
}
protected virtual void HandleDragging()
{
//Get the target position for the knob
Vector2 wantedPosition = Vector2.zero;
RectTransformUtility.ScreenPointToLocalPointInRectangle(bounds, Input.mousePosition, null, out wantedPosition);
knob.anchoredPosition = Vector2.Lerp(knob.anchoredPosition, wantedPosition, Time.deltaTime * dragSpeed);
//Find the normalized Delta for the Knob
float xDelta = knob.anchoredPosition.x / (bounds.rect.width * 0.5f);
float yDelta = knob.anchoredPosition.y / (bounds.rect.height * 0.5f);
finalDelta = new Vector2(xDelta, yDelta);
finalDelta = Vector2.ClampMagnitude(finalDelta, 1f);
}
void ResetKnob()
{
knob.anchoredPosition = Vector2.Lerp(knob.anchoredPosition, Vector2.zero, Time.deltaTime * resetSpeed);
finalDelta = Vector2.zero;
}
我正在尝试在3d空间中上下移动油门。我正在驾驶舱侧面使用3d油门对象使用鼠标点上下移动,我尝试使用上述代码移动2d精灵,效果很好但不适用于移动3d油门对象。 spri
答案 0 :(得分:0)
Mathf.Lerp(inputvalue,-10f,10f);
我认为您的错误是,当Lerp函数只能插值[0,1],Mathf.Lerp
时,您试图将输入插值到10您需要将其称为CREATE OR REPLACE TRIGGER sample
AFTER INSERT ON client
BEGIN
EXEC DBMS_SCHEDULER.RUN_JOB("JOB CONTAN PYTHON FILE");
END;
获得插值后,只需将其添加到翻译中即可
Mathf.Lerp(-10, 10, inputValue);
答案 1 :(得分:0)
找出节气门的距离:
Vector2 throttleDownPosition = Vector2.zero; // Or whatever it is. I can't tell from your code.
Vector2 throttleUpPosition = new Vector2(0f,1f); // Or whatever it is. I can't tell from your code.
Vector2 throttleCurrentPosition = knob.anchoredPosition;
// Calculate ratio between current throttle / full throttle
float throttlePercentage =
Vector2.Distance(throttleCurrentPosition, throttleDownPosition)
/ Vector2.Distance(throttleUpPosition, throttleDownPosition);
然后,使用3D节气门对象在节气门为0%时应处于什么位置和旋转:
Vector3 startPosition
Quaternion startRotation
以及当油门为100%时3D油门对象的位置和旋转:
Vector3 endPosition
Quaternion endRotation
您可以使用Vector3.Lerp
和Quaternion.Lerp
查找当前油门设置的合适位置和旋转:
Vector3 lerpedPosition = Vector3.Lerp(startPosition, endPosition, throttlePercentage);
Quaternion lerpedRotation = Quaternion.Lerp(startRotation, endRotation, throttlePercentage);
throttleObject.transform.position = lerpedPosition;
throttleObject.transform.rotation = lerpedRotation