Collision inside a local function
Trying to find a way to detect collision with my box collider... Things like Collider2D.Cast are not functional since they return the ammount of object collided and not a array/list with the id of the objects collided
Is there any OnCollisionEnter() that works inside a local function? Or any solutions for that?
Answer by Vega4Life · Dec 26, 2018 at 01:43 PM
Collder2D.Cast does have a results array.
public int Cast(Vector2 direction, RaycastHit2D[] results, float distance = Mathf.Infinity, bool ignoreSiblingColliders = true);
You set the size of the results array yourself, it will be pushed through, and get filled out with what it hit. If it hit anything. Here is an example:
RaycastHit2D[] results = new RaycastHit2D[1];
int resultCount = collider.Cast(Vector3.down, results);
If it does hit more things than the size of the results array you created, they will be ignored.
Answer by Mouroz · Jan 02, 2019 at 04:50 PM
oh ok
But is there anyhow to know the ammount of results that will be found without having to do the cast twice? (one for knowing the ammount and the other one for getting the arrays)
Your answer
Follow this Question
Related Questions
Checking for a gameobject at a position 1 Answer
Objects not colliding 1 Answer
crouch attack collider 2d question 1 Answer
rb.velocity.y sometimes requires stopping on x axis as well. 0 Answers
Collision With Text 0 Answers