So i have this script and for some reason I dont know what to set the appear rate nd the distance from player too. I also dont know how to make it so that the enemy re-appears when you walk away from it. If your confused on what I am saying then heres a basic rundown. I want it so that when the enemy dissappears as you walk away, it will re-appear later around you sort of like slenderman. Hope this clears ome confusion.
Heres the code I have:
var player : Transform; // the Object the player is controlling
var spawnOrgin : Vector3; // this will be the bottom right corner of a square we will use as the spawn area
var maximum : Vector3; // max distance in the x, y, and z direction the enemy can spawn
var spawnRate : float; // how often the enemy will respawn
var distanceToPlayer : float; // how close the enemy has to be to the player to play music
private var nearPlayer : boolean = false; // use this to stop the teleporting if near the player
private var nextTeleport : float = 0.0f; // will keep track of when we to teleport next
function Start ()
{
nextTeleport = spawnRate;
}
function 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 = 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;
}
anyone got any help for me?
So howwould i do that? I suck at coding :\
– SubZer056@leggod You are welcome. Do note the update re using Coroutines with Parse.com API... if thats what you are doing that keeps things simpler and more in the Unity style. Loom and SceneLoom are definitely useful where you need to do your own threaded dispatching.
– Huacanacha