IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
LinearDisplacement.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: Move the position of this object based on a linear mapping
4 //
5 //=============================================================================
6 
7 using UnityEngine;
8 using System.Collections;
9 
10 namespace Valve.VR.InteractionSystem
11 {
12  //-------------------------------------------------------------------------
13  public class LinearDisplacement : MonoBehaviour
14  {
15  public Vector3 displacement;
16  public LinearMapping linearMapping;
17 
18  private Vector3 initialPosition;
19 
20  //-------------------------------------------------
21  void Start()
22  {
23  initialPosition = transform.localPosition;
24 
25  if ( linearMapping == null )
26  {
27  linearMapping = GetComponent<LinearMapping>();
28  }
29  }
30 
31 
32  //-------------------------------------------------
33  void Update()
34  {
35  if ( linearMapping )
36  {
37  transform.localPosition = initialPosition + linearMapping.value * displacement;
38  }
39  }
40  }
41 }