Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to change values from a script [ScreenX for example]?

Discussion in 'Cinemachine' started by AkhmedAbasov, Feb 17, 2019.

  1. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    162
    Trying to aim the camera closer to the player and slightly move it to the right

    Code (CSharp):
    1. using Cinemachine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. namespace Appx
    7. {
    8.  
    9.     public class MainAimCMFreeLookHelper : MonoBehaviour
    10.     {
    11.         CinemachineFreeLook cinemachineComponent;
    12.  
    13.         bool isAim;
    14.  
    15.         private void Awake()
    16.         {
    17.             InputManager.OnAimKeyClicked += Aim;
    18.             cinemachineComponent = GetComponent<CinemachineFreeLook>();
    19.         }
    20.  
    21.         void Start()
    22.         {
    23.  
    24.         }
    25.  
    26.  
    27.         void OnEnable()
    28.         {
    29.             //cam.LookAt = Application.instance.Player.transform;
    30.             //cam.Follow = Application.instance.Player.transform;
    31.         }
    32.  
    33.         void Aim()
    34.         {
    35.             if (!isAim)
    36.             {
    37.                 cinemachineComponent.m_Orbits[0].m_Height = 1.9f;
    38.                 cinemachineComponent.m_Orbits[0].m_Radius = 2.02f;
    39.  
    40.                 cinemachineComponent.m_Orbits[1].m_Height = 1.93f;
    41.                 cinemachineComponent.m_Orbits[1].m_Radius = 1.65f;
    42.  
    43.                 cinemachineComponent.m_Orbits[2].m_Height = 1.42f;
    44.                 cinemachineComponent.m_Orbits[2].m_Radius = 1.97f;
    45.  
    46.                 cinemachineComponent.m_XAxis.m_MaxSpeed = 100;
    47.  
    48.                 //cinemachineComponentComposer.m_TrackedObjectOffset = new Vector3(0.8f, 1.4f, 0);
    49.             }
    50.             else
    51.             {
    52.                 cinemachineComponent.m_Orbits[0].m_Height = 3f;
    53.                 cinemachineComponent.m_Orbits[0].m_Radius = 4.9f;
    54.  
    55.                 cinemachineComponent.m_Orbits[1].m_Height = 2.5f;
    56.                 cinemachineComponent.m_Orbits[1].m_Radius = 5f;
    57.  
    58.                 cinemachineComponent.m_Orbits[2].m_Height = 1.5f;
    59.                 cinemachineComponent.m_Orbits[2].m_Radius = 5.83f;
    60.  
    61.                 cinemachineComponent.m_XAxis.m_MaxSpeed = 250;
    62.  
    63.                 //cinemachineComponentComposer.m_TrackedObjectOffset = new Vector3(0f, 1.4f, 0);
    64.             }
    65.  
    66.        
    67.         }
    68.  
    69.    
    70.  
    71.     }
    72. }
    2222222.png


    But I can't figure out how to get or change all the fields? For example ScreenX?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    You need freeLook.GetRig(n).GetCinemachineComponent<CinemachineComposer>().m_TrackedObjectOffset and .m_ScreenX, where n = 0...2
     
  3. ColtPtrHun

    ColtPtrHun

    Joined:
    Nov 20, 2019
    Posts:
    9
    Many thanks!
     
  4. Le_Jo

    Le_Jo

    Joined:
    Jan 24, 2019
    Posts:
    13
    Thank you ! :D
    For those who (like me) didn't get it fast, it should looks like this :


    GetComponent<CinemachineVirtualCamera>().GetCinemachineComponent<CinemachineComposer>().m_ScreenX = 0.33f;

    I didn't find a good ressource for all the C# stuff with Cinemachine thow T-T
     
  5. d2clon

    d2clon

    Joined:
    Aug 19, 2017
    Posts:
    19
    What worked for me:

    Code (CSharp):
    1. cinemachineframingTransposer = GetComponent<CinemachineVirtualCamera>().GetCinemachineComponent<CinemachineFramingTransposer>();
    Notice I am using `CinemachineFramingTransposer` no `CinemachineComposer`
     
  6. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    88
    failed ,or i
    dont know how to do it
    var composerha = vcam.GetCinemachineComponent<CinemachineFramingTransposer>();
    composerha.ScreenX = 1f;
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Try
    composerha.m_ScreenX = 1f;