Labo_2_equ_2_a15/Assets/Scripts/EnemyBehavior.cs
JoelLapointe86 beba09bcb4 ajout animation + flip de l'ennemi
ajout de l'animation de marche de l'ennemi + copie de flip pour
l'ennemi( non refactor)

ajout des modifs dans la master Scene
2015-11-10 21:10:28 -05:00

43 lines
970 B
C#

using UnityEngine;
using System.Collections;
public class EnemyBehavior : MonoBehaviour {
private float direction = 1.0f;
private Rigidbody2D rb;
private bool facingRight = true;
// 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;
if ((direction < 0 && facingRight) || (direction > 0 && !facingRight))
flip();
}
private void flip()
{
facingRight = !facingRight;
Vector3 scale = transform.localScale;
scale.x *= -1;
transform.localScale = scale;
}
}