docs.unity.cn
Search Results for

    Show / Hide Table of Contents

    Method ConvertUnityObjectToType

    ConvertUnityObjectToType<T>(Object)

    Returns a component of the specified type that is associated with an object, if possible.

    Declaration
    public static T ConvertUnityObjectToType<T>(Object objectIn) where T : class
    Parameters
    Type Name Description
    Object objectIn

    The Unity Object reference to convert.

    Returns
    Type Description
    T

    A component of type T, if found on the object. Otherwise returns null.

    Type Parameters
    Name Description
    T

    The type to convert to.

    Remarks

    If the objectIn is the requested type, then this function casts it to type T and returns it.

    If objectIn is a GameObject, then this function returns the first component of the requested type, if one exists.

    If objectIn is a different type of component, this function returns the first component of the requested type on the same GameObject, if one exists.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)