31 lines
946 B
C#
31 lines
946 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EnemyController_Jumper : MonoBehaviour {
|
|
[SerializeField] Rigidbody2D body;
|
|
[SerializeField] float diff = 10.0f;
|
|
[SerializeField] float jumpSpeed = 200f;
|
|
[SerializeField] float runSpeed = 10f;
|
|
|
|
// Start is called before the first frame update
|
|
void Start() {
|
|
body = GetComponent<Rigidbody2D>();
|
|
StartCoroutine(PickSomewhere());
|
|
}
|
|
|
|
IEnumerator PickSomewhere() {
|
|
while (true) {
|
|
yield return new WaitForSeconds(100.0f / diff);
|
|
if (Random.Range(0.0f, 1.0f) > 0.5) {
|
|
body.velocity = new Vector2(Random.Range(-1.0f, 1.0f) * runSpeed, body.velocity.y);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate() {
|
|
body.velocity = new Vector2(body.velocity.x, Mathf.Clamp(body.velocity.y, -1*jumpSpeed, jumpSpeed));
|
|
}
|
|
}
|