how to make point spawn random on screen after collected
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collect : MonoBehaviour
{
private Rigidbody2D rb;
//this goes on player as a script
[SerializeField]
private GameObject Point;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
SpawnPoint();
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
}
private void SpawnPoint()
{
bool pointSpawned = false;
while (!pointSpawned)
{
//replace the range with points on your camera, first is X cord second is Y cord
Vector3 pointPosition = new Vector3(Random.Range(-13f, 13f), Random.Range(-8f, 8f), 0f);
if ((pointPosition - transform.position).magnitude < 3)
{
continue;
}
else
{
Instantiate(Point, pointPosition, Quaternion.identity);
pointSpawned = true;
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
Destroy(collision.gameObject);
SpawnPoint();
}
}