I have an issue, and I'm not sure why it's happening. I have a prefab that I've built in a colour-changing game. It has the following:
- Four 2D objects that if they collide with the player (2D collider attached to all), they cause the player to die.
- One 2D object that if the player strikes, it generates a duplicate of itself with the Instantiate function.
All 2D objects are created; The four objects that cause the player to die are being created as normal and continue to cause the player to die. However, the object that instantiates the prefab and increments the score can no longer be collided with. The player appears to pass behind it. I'm pasting my code below. I would really appreciate if anyone can offer advice on this:
void Update () {
if (Input.GetButtonDown("Jump") || Input.GetMouseButtonDown(0))
{
thing.velocity = Vector2.up * bounciness;
}
scoreText.text = score.ToString();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "plusScore")
{
score++;
Destroy(collision.gameObject);
Instantiate(barrier, new Vector2(transform.position.x, transform.position.y + 7f), transform.rotation);
return;
}
if(collision.tag != currentColour)
{
Debug.Log("You DIED!");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
score = 0;
}
}