the lines of code that are inside of the OnBecameVisible method doesn’t work at all, why?
using UnityEngine;
using System.Collections;
public class EnemyScript : MonoBehaviour {
private Transform EnemyTransform01;
public float Enemy01MaxSpeed = 40f;
public float Enemy01MinSpeed = 10f;
private float CurrentXsDirection1 = 1;
private float CurrentXsDirection2 = 4;
// Use this for initialization
void Start () {
EnemyTransform01 = transform;
}
// Update is called once per frame
void Update () {
EnemyTransform01.Translate (Vector3.forward * Random.Range (Enemy01MinSpeed, Enemy01MaxSpeed) * Time.deltaTime);
if (EnemyTransform01.position.z >= 0) {
Destroy (this.gameObject);
}
}
void OnBecameVisible() {
float XtimerDirection = 4f;
EnemyTransform01.Translate (Vector3.left * Random.Range (Enemy01MinSpeed, Enemy01MaxSpeed) * Time.deltaTime);
XtimerDirection -= Time.deltaTime;
if (XtimerDirection <= 2) {
XtimerDirection = 4f;
};
if (XtimerDirection <= 3) {
EnemyTransform01.Translate (Random.Range (CurrentXsDirection1, CurrentXsDirection2), 0, 0 * Time.deltaTime);
};
if (XtimerDirection <= 2.5) {
EnemyTransform01.Translate (-Random.Range (CurrentXsDirection1, CurrentXsDirection2), 0, 0 * Time.deltaTime);
};
}
void OnTriggerEnter (Collider enemycollider)
{
if (enemycollider.CompareTag("PlayerWeapon"))
{
Destroy(this.gameObject);
}
}
}