Hi,
This is the updated script.
My player constantly changes position, when he moves a message is sent (Direction) to spawn a particle.
The problem I am having is that even though most of the particles spawn offscreen, some still spawn on screen.
Script.js
#pragma strict
var particle : GameObject;
var left : Transform;
var right : Transform;
var top : Transform;
var bottom : Transform;
var spawnRight : boolean;
var spawnLeft : boolean;
var spawnTop : boolean;
var spawnBottom : boolean;
function Start () {
InvokeRepeating("SpawnUpdate", 0.5, Random.Range(0.3, 1.5));
}
function LateUpdate () {
right.localPosition.y = Random.Range(-4.5, 4.5);
left.localPosition.y = Random.Range(-4.5, 4.5);
top.localPosition.x = Random.Range(-6.8, 6.8);
bottom.localPosition.x = Random.Range(-6.8, 6.8);
}
function SpawnUpdate () {
if (spawnRight) {
Instantiate(particle, right.position, particle.transform.rotation);
}
if (spawnLeft) {
Instantiate(particle, left.position, particle.transform.rotation);
}
if (spawnTop) {
Instantiate(particle, top.position, particle.transform.rotation);
}
if (spawnBottom) {
Instantiate(particle, bottom.position, particle.transform.rotation);
}
}
function Direction (direction : Vector3) {
if (direction.x > 0 || direction.y > 0) {
spawnLeft = false;
spawnTop = true;
spawnBottom = false;
spawnRight = true;
}
if (direction.x < 0 || direction.y < 0) {
spawnLeft = true;
spawnTop = false;
spawnBottom = true;
spawnRight = false;
}
if (direction.y > 0 || direction.x < 0) {
spawnLeft = true;
spawnTop = true;
spawnBottom = false;
spawnRight = false;
}
if (direction.y < 0 || direction.x > 0) {
spawnLeft = false;
spawnTop = false;
spawnBottom = true;
spawnRight = true;
}
}
Thanks in advance!
↧