'Unity3D OnTriggerEnter2D is never called
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickupCoin : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
Destroy(this.gameObject);
Debug.Log("Coin was picked up");
}
}
}
Script is assigned to randomly spawned sprites, but player cannot interact with them, and Debug is never called. This means method is never called for reasons unknown to me.
If you need additional info I can provide it.
Solution 1:[1]
First, just check if the player and the created sprites have a Box Collider component.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Super3283u |
