Files
ihob/Assets/PegLegIo/scripts/EnemyController_Shooter.cs

27 lines
792 B
C#
Raw Permalink Normal View History

2026-02-21 17:04:05 -08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyController_Shooter : MonoBehaviour {
[SerializeField] Rigidbody2D body;
[SerializeField] float diff = 20.0f;
[SerializeField] float minSpeed = 20f;
[SerializeField] float maxSpeed = 100f;
// Start is called before the first frame update
void Start() {
body = GetComponent<Rigidbody2D>();
if (transform.position.x < 0) {
body.velocity = new Vector2(Random.Range(minSpeed, maxSpeed), 0);
} else {
body.velocity = new Vector2(-1.0f*Random.Range(minSpeed, maxSpeed), 0);
}
}
private void FixedUpdate() {
if (Mathf.Abs(transform.position.x) > 480) {
Destroy(gameObject);
}
}
}