本文整理汇总了C#中GameObject.GetComponentsInParent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponentsInParent方法的具体用法?C# GameObject.GetComponentsInParent怎么用?C# GameObject.GetComponentsInParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetComponentsInParent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsRobot
// Returns true if the given game object is part of a Robot
private bool IsRobot(GameObject gObject){
if (gObject.tag.Equals("Circle")){
return false;
}
if (gObject.tag.Equals("Robot")){
return true;
}
else {
foreach (Transform childTrans in gObject.GetComponentsInChildren<Transform>()){
if (childTrans.gameObject.tag.Equals("Robot")){
return true;
}
}
foreach (Transform parentTrans in gObject.GetComponentsInParent<Transform>()){
if (parentTrans.gameObject.tag.Equals("Robot")){
return true;
}
}
}
return false;
}
示例2: FindGameObjectWithTagInParents
private GameObject FindGameObjectWithTagInParents(GameObject start, string tag)
{
Transform[] parents = start.GetComponentsInParent<Transform>();
foreach (Transform parent in parents)
{
if (parent.gameObject.CompareTag (tag))
return parent.gameObject;
}
return null;
}
示例3: trapOther
private void trapOther(GameObject thing)
{
if (thing.rigidbody)
{
thing.rigidbody.velocity = Vector3.zero;
thing.rigidbody.useGravity = false;
trappedRigidbodies.Add(thing.rigidbody);
}
if (thing.GetComponentsInChildren<Rigidbody>().Length > 0)
{
foreach (Rigidbody body in thing.GetComponentsInChildren<Rigidbody>())
{
body.velocity = Vector3.zero;
body.useGravity = false;
trappedRigidbodies.Add(body);
}
}
if (thing.GetComponentsInParent<Rigidbody>().Length > 0)
{
foreach (Rigidbody body in thing.GetComponentsInParent<Rigidbody>())
{
body.velocity = Vector3.zero;
body.useGravity = false;
trappedRigidbodies.Add(body);
}
}
trappedThings.Add(thing);
}
示例4: GetDirectFocusContainerComponent
public static FocusContainer GetDirectFocusContainerComponent(GameObject p_child)
{
if(p_child != null)
{
FocusContainer[] v_parentsFocus = p_child.GetComponentsInParent<FocusContainer>();
FocusContainer v_directParentFocus = null;
foreach(FocusContainer v_parentFocus in v_parentsFocus)
{
if(v_parentFocus != null && v_parentFocus.enabled)
{
v_directParentFocus = v_parentFocus;
break;
}
}
return v_directParentFocus;
}
return null;
}