hi, can anyone help me to find a code where objects are re-spawning in a random position once it exits the game screen and have a timer on it so it loops again (what my object does- enter game screen then object moves on it’s own then exits) but at a random position again (and continues). sorry for my English… if anyone can help or give me a link to something that can help, that would be awesome!!! thank you
Here is an example you can use:
using UnityEngine;
using System.Collections;
//Attach this script to your object.
public class Example : MonoBehaviour {
public Camera mainCamera; //Drag and drop your camera here.
bool IsInCameraView()
{
return GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(mainCamera), GetComponent<Renderer>().bounds);
}
void Update()
{
if(!IsInCameraView()) //If the object is not in the view of the camera.
{
//Your random spawning text.
}
}
}