Teleporting Problem

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

Wrong forum, please use code tags as it’s very hard to read unformatted code.

Sorry I completely new to the forums and don’t know what forum or how to put the code tags in sorry

Double Check your bounds that they actually match the map, also the map origin should be a corner position, the default is generally the mid-point.

Use [plain]``[/plain]

Sorry for this probably stupid question but how would I check the bounds also if you know any links to tutorials for unity and the coding could you link them so I can learn more?

I’ve wrote up a blog post about the path I personally took to get to the point of being capable of programming in Unity. It’s no magic pill, but it will help you get started with some resources:
http://www.disastercake.com/blog/how-disastercake-learned-to-program-with-unity-tutorials/

Goodluck!

Add two cubes and in the code move one to the origin and the other the the maxRange using the “transform.position” code in your example.

Thank you to everyone for replying to this thread and helping me hopefully I can learn more from the tutorials some of you left for me thank youall