holopy3/Assets/SteamVR/InteractionSystem/Core/Scripts/LinearDisplacement.cs

42 lines
981 B
C#
Raw Permalink Normal View History

2020-12-10 14:25:12 +00:00
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: Move the position of this object based on a linear mapping
//
//=============================================================================
using UnityEngine;
using System.Collections;
namespace Valve.VR.InteractionSystem
{
//-------------------------------------------------------------------------
public class LinearDisplacement : MonoBehaviour
{
public Vector3 displacement;
public LinearMapping linearMapping;
private Vector3 initialPosition;
//-------------------------------------------------
void Start()
{
initialPosition = transform.localPosition;
if ( linearMapping == null )
{
linearMapping = GetComponent<LinearMapping>();
}
}
//-------------------------------------------------
void Update()
{
if ( linearMapping )
{
transform.localPosition = initialPosition + linearMapping.value * displacement;
}
}
}
}