2
\$\begingroup\$
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraInformation : MonoBehaviour
{
    public string currentCameraState;

    // Start is called before the first frame update
    void Start()
    {
        var components = new List<Component>();
        foreach (var component in GetComponents<Component>())
        {
            if (component != this)
            {
                var fullName = component.GetType().FullName;
                if (fullName.StartsWith("Cinemachine"))
                {
                    currentCameraState = component.
                }
            }
        }
    }

    // Update is called once per frame
    void Update()
    {

    }

    private void OnEnable()
    {

    }

    private void OnDisable()
    {

    }
}

At this line I want to assign the string the component status if it's enabled true or false.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Not all Component types in Unity have an enabled state. what specific components do you want to check for? it looks like the relevant Cinemachine types all derive from MonoBehaviour, which has an enabled property you can read, as the barest glance at the documentation would confirm. Did you try searching for MonoBehaviour instead of Component? \$\endgroup\$
    – DMGregory
    Nov 7, 2020 at 5:38

1 Answer 1

3
\$\begingroup\$

A MonoBehaviour has an enabled property you can check. So:

currentCameraState = component.enabled ? "Cinemachine is enabled" : "Cinemachine is disabled";
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Note that the .enabled property is not available on the Component type OP is using. So you would need to cast this so a more derived type. \$\endgroup\$
    – DMGregory
    Nov 7, 2020 at 5:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .