Projectile colliding with player at origin,Excluding a specific game object
1) Player shoots a laser beam 2) Laserbeam prefab collides immediately with player 3) SceneManager resets scene
I suspect two possible causes:
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
var projectile = Instantiate(
projectilePrefab,
transform.position,
projectilePrefab.transform.rotation);
}
}
OR
private void OnCollisionEnter2D(Collision2D collision)
{
SceneManager.LoadScene(0);
//if collider is projectile.Prefab, don't run this piece of code
}
I'm suspecting that either the origin of my laserbeam is causing this problem or the fact that my laserbeam collision doesn't exclude the player.
One solution for this would be to ensure the laserbeam spawns away from the player, so they do not collide. Ideally, however, the collider on my player would be able to simply exclude contact with a laserbeam as cause for SceneManager to reset the scene.
Where I get stuck when it comes to testing these solutions is the exact syntax. I was hoping someone might be willing to give some insight that is adept at conditional statements and the like. I'm still super new, so there are a lot of gaps, though I have a basic understanding.
Essentially what my ideal might look like (so far as I can tell) is: "If collider is projectilePrefab, do not run SceneManager.LoadScene"
Cheers and thank you in advance,
private void OnCollisionEnter2D(Collision2D collision)
{
SceneManager.LoadScene(0);
//if collider is projectile.Prefab, don't run this piece of code
}
Your answer
Follow this Question
Related Questions
Projectile colliding with player at origin,Excluding a specific game object 0 Answers
OnCollisionEnter2D not calling, but objects are colliding. 1 Answer
Detect whether a Rigidbody collided with a Trigger 2 Answers
I cant get 2D collisions to work, but everything looks ok to me, any help please? 4 Answers
Issues with 2D collision/overlap detection,Help detecting 2D collision/overlap 0 Answers