Skip to content

Instantly share code, notes, and snippets.

@ChigusaApp
Last active September 2, 2019 06:43
Show Gist options
  • Save ChigusaApp/8b2dc757a1ad254cd29db40dace5be6b to your computer and use it in GitHub Desktop.
Save ChigusaApp/8b2dc757a1ad254cd29db40dace5be6b to your computer and use it in GitHub Desktop.
[#Unity] GetComponent Sample
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetComponentSample : MonoBehaviour
{
private bool Flag { get; set; }
private void Awake()
{
Debug.Log($"{name} : in Awake");
}
void Start()
{
Debug.Log($"{name} : in Start");
Debug.Log($"{name} : current position is {GetComponent<Transform>().position}");
Debug.Log($"{name} : child name is {GetComponentInChildren<GetComponentSample>()?.name}");
Debug.Log($"{name} : child (includeActive) name is {GetComponentInChildren<GetComponentSample>(true)?.name}");
Debug.Log($"{name} : parent name is {GetComponentInParent<GetComponentSample>()?.name}");
Debug.Log($"{name} : current component length is {GetComponents<Transform>()?.Length}");
Debug.Log($"{name} : children component length is {GetComponentsInChildren<Transform>()?.Length}");
Debug.Log($"{name} : children (includeActive) component length is {GetComponentsInChildren<Transform>(true)?.Length}");
Debug.Log($"{name} : prarent component length is {GetComponentsInParent<Transform>()?.Length}");
}
void Update()
{
if (!Flag)
Debug.Log($"{name} : in Update");
Flag = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment