I am working with random instantiation but i don’t want it to instantiate inside my player as they move. How would I achieve this? The only thing I could find was Physics2D.OverlapCircle but I don’t know how to implement it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeleteAndSpawn : MonoBehaviour
{
int _score = 0;
public GameObject Collectable;
UIManager UiManagerVar;
//float TimerforCollectable = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
UiManagerVar = GameObject.Find("Canvas").GetComponent<UIManager>();
Collectable = GameObject.FindGameObjectWithTag("Finish");
//timerforCollectionFunc();
Debug.Log(TimerforCollectable);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
Instantiate(Collectable, new Vector3(Random.Range(-4, 4), Random.Range(-4, 4), 0), Quaternion.identity);
Destroy(this.gameObject, 0);
UiManagerVar.UpdateofNumberEnemy();
// if player has entered the collision zone, prevent other collision detection
}
else if (collision.tag == "PlayerMove")
{Instantiate(Collectable, new Vector3(Random.Range(-4, 4), Random.Range(-4, 4), 0), Quaternion.identity);
Destroy(this.gameObject, 0);
UiManagerVar.UpdateofNumber();
}
}
/*public void timerforCollectionFunc()
{
TimerforCollectable += Time.deltaTime;
}*/
}