Search Unity

Set follow target and look at target with C# script

Discussion in 'Cinemachine' started by K97, Feb 10, 2018.

  1. K97

    K97

    Joined:
    Mar 24, 2016
    Posts:
    10
    I am trying to set "look at" and "follow" targets at Cinemachine Virtual Camera through scripting (C#), but i am getting some errors. Is this appropriate way to do that?


    CinemachineVirtualCamera followCam;

    void Start ()
    {
    followCam = GameObject.Find("Cameras").GetComponent<CinemachineVirtualCamera>();

    followCam.LookAt = GameObject.FindGameObjectWithTag("Chatacter"); // This produces following error:

    // Error CS0029 Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.Transform


    followCam.Follow = GameObject.FindGameObjectWithTag("Character"); //This produces following error:
    // Error CS0029 Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.Transform

    }
     
  2. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Add
    Code (CSharp):
    1. .transform
    after FindGameObjectWithTag()
     
    K97 likes this.