How to make a camera go to a location in Unity (c#)?

Viewed 51

I'm currently trying to make a camera go to an object when right click is held however it's not working how do I fix this? When the button right click is pressed it prints hi and hello however the camera does not move.

Edit: The line "transform.localPosition = MagicWandReg1Pos;" and " transform.localPosition = CameraReg1Pos;" is what i think is the problem but i just don't know how to fix it.

Edit 2: the problem is the addon cinemachine (i think ) I'm currently working on fixing it).

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Camscript : MonoBehaviour
 {
     public Vector3 MagicWandReg1Pos;
     public Vector3 CameraReg1Pos;
     
     // Start is called before the first frame update
     void Start()
     {
         Cursor.lockState = CursorLockMode.Locked;
         MagicWandReg1Pos = new Vector3(0.9525713f,2,2400557f);
         CameraReg1Pos = new Vector3(-5.601483f,3,150208);
         transform.localPosition = CameraReg1Pos;
     }
 
     // Update is called once per frame
     void Update()
     {
       
         
           if (Input.GetKeyDown(KeyCode.Mouse1))
           {
     transform.localPosition = MagicWandReg1Pos;
 print("Hello");
           }
 if (Input.GetKeyUp(KeyCode.Mouse1))
           {
     transform.localPosition = CameraReg1Pos;
     print("Hi");
           }
          
     }
 }
0 Answers
Related