bool isCollided; // For dying animation void OnEnable() { transform.localScale = new Vector3(1f, 1f, 1f); // For Random movement type randRotationMaxTimer = Random.Range(0f, 0.5f); randRotationTimer = 0f; randRotation = Random.rotation; currentMovementType = EnemyStat.MovementType.Straight; currentSpawnedTimer = 0f; isCollided = false; GetComponent <CircleCollider2D>().enabled = false; }
void Update() { float p_turnSpeed = es.turnSpeed * Time.deltaTime * gd.gameSpeed; // TODO: Improve initial spawn state timer (this feature helps enemies go in a straight line first // before reverting to its set movement type) by not making it timer based so that there is // no need to test this feature with each new enemy creation if (HelperFunctions.hf.Timer(ref currentSpawnedTimer, 1f)) { currentMovementType = es.movementType; GetComponent <CircleCollider2D>().enabled = true; } switch (currentMovementType) { case EnemyStat.MovementType.Straight: MoveStraight(); break; case EnemyStat.MovementType.Seeking: WarpObject(); transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.forward, ObjectManager.om.head.transform.position - transform.position), p_turnSpeed); MoveStraight(); break; case EnemyStat.MovementType.Random: WarpObject(); // Get a random timer HelperFunctions.hf.Timer(ref randRotationTimer, randRotationMaxTimer); if (randRotationTimer <= 0f) { randRotationMaxTimer = Random.Range(0f, 3f); randRotation = Random.rotation; } // Rotate towards random direction Quaternion newRotation = Quaternion.Lerp(transform.rotation, randRotation, p_turnSpeed); newRotation.x = newRotation.y = 0f; transform.rotation = newRotation; MoveStraight(); break; case EnemyStat.MovementType.Distance: break; case EnemyStat.MovementType.Teleport: break; default: break; } if (isCollided) { StartCoroutine("DeathAnimation"); if (transform.localScale.x <= .1f) { ObjectManager.om.RemoveObject(this.gameObject); } } }