Search Unity

Camera not Changing Position

Discussion in 'VR' started by cyenketswamy, May 23, 2018.

  1. cyenketswamy

    cyenketswamy

    Joined:
    Jul 24, 2015
    Posts:
    41
    I am trying to change the camera position when the Motion controller trigger button is pressed. Only the text updates which confirms that the trigger press returns true. However the call to explictly change the camera position doesnt work.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.XR.WSA.Input;
    4.  
    5. //Script is attached to the camera
    6. public class CameraController : MonoBehaviour {
    7.     TextMesh txtMesh;
    8.     GameObject displayText;
    9.     // Use this for initialization
    10.     void Start () {
    11.  
    12.         InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
    13.         displayText = GameObject.FindWithTag("StatusText");
    14.         txtMesh = displayText.GetComponent<TextMesh>();
    15.     }
    16.  
    17.     private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
    18.     {
    19.         if (obj.state.selectPressed)
    20.         {
    21.             transform.position = new Vector3(-5.71f, 1.0f, -2.23f);//Change the position of the camera from (0.0f,1.0f,-2.23f) not working
    22.             txtMesh.text = "Trigger Pressed";//ok
    23.         }
    24.     }
    25.  
    26.     // Update is called once per frame
    27.     void Update () {
    28.        
    29.  
    30.     }
    31.  
    32.     private void OnDestroy()
    33.     {
    34.         InteractionManager.InteractionSourceUpdated -= InteractionManager_InteractionSourceUpdated;
    35.     }
    36. }
    37.  
     
  2. cyenketswamy

    cyenketswamy

    Joined:
    Jul 24, 2015
    Posts:
    41
    Ok found a solution. The camera needs to be added as a child of another object which you move.