OnMouseDown in prefab not working with some scene

213 Views Asked by At

I have prefab enemyRangeAttack and then I add this code for enemy (child of enemyRangeAttack)

public class Selectable : MonoBehaviour{

[HideInInspector] public GameObject Player;
public float range = 10f;

private void Awake()
{
    Player = GameObject.FindGameObjectWithTag("Player");
}


private void OnMouseDown()
{
    Debug.LogWarning("Mouse down "+ gameObject);

    float dist = Vector3.Distance(Player.transform.position, transform.position);

    if (dist < range)
    {
        Selected();
    }

}

public void Selected()
{
   GameObject newSelection = ObjectPooler.instance.SpawnFromPool(
            "Mark",
            transform.GetChild(0).gameObject.transform.position,
            Quaternion.identity
        );
    newSelection.transform.SetParent(transform);
}
}

Game object enemyRangeAttack have circle collider2d and trigger is on and Game object enemy have too

And I have 3 scene, method OnMouseDown() not working for all my scene. How can I fix this

0

There are 0 best solutions below