Search Unity

Change camera position

Discussion in 'Getting Started' started by Baolo, Feb 8, 2016.

  1. Baolo

    Baolo

    Joined:
    Feb 8, 2016
    Posts:
    3
    Hello,

    I'm trying to make an application where when I press the right arrow I move the camera toward a predefine position. I tried with this code but it don't work.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MovePOV : MonoBehavior {
    5.    public Vector3 initialPosition;
    6.    public Vector3 modifPosition ;
    7.  
    8.    void Start ( ) {
    9.       transform. position = initialPosition;
    10.    }
    11.  
    12.    void Update ( ) {
    13.       if (Input.GetKeyDown (Keycode.RightArrow))
    14.          transform.position = modifPosition;
    15.    }
    16. }
    I searched solutions on the Web and I did't find what I needed.
    Does someone can explain me why this code don't work for what I want to do.
    Thanks.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Looks right to me, assuming you want the whatever this script is attached to to jump to modifPosition when the right arrow is pressed. In what way does it not work?
     
  3. Baolo

    Baolo

    Joined:
    Feb 8, 2016
    Posts:
    3
    You're right. This script work properly when I use it alone.
    I forgot to specify that i'm using a custom package where I use an Oculus. So I think the problem come from it. I Will check about.
    Thanks you for your answer and sorry for didn't check the script alone before
     
    JoeStrout likes this.