[Unity] 자식 객체의 Collision을 얻는 방법
설명
아이의 스크립트로 부모의 스크립트 취득해 거기에 함수의 인수에 Collision,collider 를 넣어 부모 객체의 함수가 참조된다고 하는 구조입니다.
자식 객체
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackCol : MonoBehaviour
{
GameObject moveControl;
MoveControl moveControlScript;
// Use this for initialization
void Start()
{
moveControl = transform.parent.gameObject;
moveControlScript = moveControl.GetComponent<MoveControl>();
}
void Update()
{
}
//親のmoveControlスクリプトで判定
private void OnTriggerStay(Collider other)
{
//Debug.Log("Attack col");
moveControlScript.AttackStay(other);
}
//親のmoveControlスクリプトで判定
private void OnTriggerExit(Collider other)
{
//Debug.Log("Attack col");
moveControlScript.AttackExit(other);
}
}
상위 객체
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveControl : MonoBehaviour
{
private bool isAttack;
void Start()
{
isAttack = false;
}
void Update()
{
}
//子のTriggerStay
public void AttackStay(Collider other)
{
//ここに処理を書く
}
//子のTriggerExit
public void AttackExit(Collider other)
{
//ここに処理を書く
}
}
Reference
이 문제에 관하여([Unity] 자식 객체의 Collision을 얻는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/maid_chan/items/faea3a20f9ed7199099e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)