- Home /
 
 
               Question by 
               nera8 · Apr 23, 2012 at 04:09 PM · 
                cameramovementgameobjectsnapping  
              
 
              Camera Movement
Hey guys,
I'm trying to make my main camera snap to a position of an empty gameobject by a press of a button, for about five seconds then return to its normal target (player) Please and Thank you ;) a code snippet in C# would be much appreciated!
               Comment
              
 
               
              Answer by asafsitner · Apr 23, 2012 at 05:32 PM
Something like this might help:
 using UnityEngine;
 using System.Collections;
 
 public class CameraMove : MonoBehaviour
 {
     private Vector3 _initialPosition;
     private Vector3 _targetPosition;
     private bool _inTargetPosition;
     
     void Update()
     {
         if(Input.GetKeyDown(KeyCode.Space) && !_inTargetPosition)
             StartCoroutine("MoveCamera");
     }
 
     IEnumerator MoveCamera()
     {
         _inTargetPosition = true;
         transform.position = _targetPosition;
         yield return new WaitForSeconds(5);
         transform.position = _initialiPosition;
         _inTargetPosition = false;
     }
 }
 
              Your answer