mirror of
https://github.com/ConjureETS/Labo_2_equ_2_a15.git
synced 2026-03-24 01:21:07 +00:00
29 lines
699 B
C#
29 lines
699 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class EnemyBehavior : MonoBehaviour {
|
|
|
|
private float direction = 1.0f;
|
|
private Rigidbody2D rb;
|
|
|
|
// Ground
|
|
public GameObject ground;
|
|
private Bounds groundBounds;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
rb = GetComponent<Rigidbody2D>();
|
|
|
|
groundBounds = ground.GetComponent<Renderer>().bounds;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate () {
|
|
if ((direction > 0 && transform.position.x >= groundBounds.max.x) ||
|
|
(direction < 0 && transform.position.x <= groundBounds.min.x))
|
|
direction *= -1.0f;
|
|
|
|
rb.velocity = Vector2.right * direction;
|
|
}
|
|
}
|