how should i call or summon my child...
Hi guys really nice to meet yall :3
ok.
I got a character and it has a child object (invisible trigger collider). the child is like attack box or attack range. if something nasty is in that area of box (IN RANGE), player character will stop moving and swing his axe like maniac.
so i used OnTriggerStay2D on player character script to detect enemy.
void OnTriggerStay2D(Collider2D collider)
{
if (collider.gameObject == Target)
{
Debug.Log("Swinging AXE >:0");
}
}
and it worked fine! but as you can see i didn't use THAT child object. instead, i just made secondary trigger collider on player character. because i don't know how to call or summon child or other external object to the script and apply it to OnTriggerStay2D method...
so noob q_q.
can you teach me how to call child (or out side object) and apply to OnTriggerStay2D method?
Answer by G4merSylver · Aug 14, 2016 at 09:47 AM
MonoBehaviour.OnEnterTrigger(); - I am quoting from the Script Reference, "Sent when another object enters a trigger collider attached to this object (2D physics only)." meaning, if you want to use it as a child you have to write a script just for the child object, then you can just return a boolean to your parent script. You can simply get the value by making a reference or using GetComponent.
Another alternative would be using Physics2D.OverlapCircle - which would completely eleminate the need for the child collider.
Your answer
Follow this Question
Related Questions
What is the best way to script a trigger that moves a object from point a to point b in C# (unity 5) 0 Answers
Enable Multiple Box Collides From Parent Object 2 Answers
What is the best way to script a trigger that moves a object from point a to point b in C# (unity 5) 1 Answer
OnTriggerEnter2D() does not work !!! 0 Answers
How do I make an object that only passes through certain objects? 1 Answer