i have a script which i found and it works fine i attached it to a capsule to check and it teleports but after it does i found that it dissapears so after pausing i found that it was just standing outside the map here is the script
using UnityEngine;
using System.Collections;
public class Teleporter : MonoBehaviour
{
public Transform player; // the Object the player is controlling
public Vector3 spawnOrgin; // this will be the bottom right corner of a square we will use as the spawn area
public Vector3 maximum; // max distance in the x, y, and z direction the enemy can spawn
public float spawnRate; // how often the enemy will respawn
public float distanceToPlayer; // how close the enemy has to be to the player to play music
private bool nearPlayer = false; // use this to stop the teleporting if near the player
private float nextTeleport = 0.0f; // will keep track of when we to teleport next
void Start ()
{
nextTeleport = spawnRate;
}
void Update ()
{
if (!nearPlayer) // only teleport if we are not close to the player
{
if (Time.time > nextTeleport) // only teleport if enough time has passed
{
transform.position = new Vector3( Random.Range(spawnOrgin.x, maximum.x), Random.Range(spawnOrgin.y, maximum.y), Random.Range(spawnOrgin.z, maximum.z) ); // teleport
nextTeleport += spawnRate; // update the next time to teleport
}
}
if (Vector3.Distance(transform.position, player.position) <= distanceToPlayer)
{
if (audio audio.clip !audio.isPlaying) // play the audio if it isn’t playing
audio.Play();
nearPlayer = true;
}
else
{
if (audio)
audio.Stop();
nearPlayer = false;
}
}
}
could anyone help me solve this