directly altering cinemachine variables

i need the camera to shift down when it hits a trigger and the only way i can think of doing this is altering the y dampening and offset from the cinemachinevirtualcamera component so i tried doing getcomponent (im not capitalizing on forums cause im lazy but i did at the proper capitalization.) and i got an error saying it couldnt find it. is there any way i can either directly alter virtual camra variables or is there another way to dynamicaly change the offset?

Are you doing that on the actual correct GameObject, eg the one with this vcam on it?

ok i think i figured it out i was being an idiot and using unityengine not Cinemachine

so i can do this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class Cameraoffsetchange : MonoBehaviour
{
    public CinemachineVirtualCamera Camera;
  
    // Start is called before the first frame update
    void Start()
    {
      
      
    }

but i still need to set the cameras gameobject inside the script so i need to do the cinemachine equivelant of Gameobject.find but it wont let me do that so i ave no idea
// Update is called once per frame
void Update()
{

}
}

Remember the first rule of GameObject.Find():

Do not EVER use GameObject.Find();

More information: https://starmanta.gitbooks.io/unitytipsredux/content/first-question.html

You already have this code:

Drag it in right in the editor! That’s the point! :slight_smile:

Kurt

i would but i need it to automaticaly refind the camera every time an old camera is destroyed lol

i got it working with a really bad fix. i made a new script attached it to the camera in the prefab and just altered the variables of that script from the external script and the script attached to the camera handles all the cinemachine stuff so i dont actualy have to find anything

Again, MANY better ways than GameObject.Find(). Read manta’s links above. Even a simple MonoBehaviour with zero functions or variables in it called IAmTheCameraYouSeek.cs is a better choice, and then you just put that on your camera and look for it.

ok i see now lol i never realized how laggy gameobject.find isill start using withtag from now on lol

1 Like