Last active
September 2, 2019 06:43
-
-
Save ChigusaApp/8b2dc757a1ad254cd29db40dace5be6b to your computer and use it in GitHub Desktop.
[#Unity] GetComponent Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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