35 lines
723 B
C#
35 lines
723 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Enemy : MonoBehaviour
|
|
{
|
|
public float maxSpeed;
|
|
private Rigidbody2D rb;
|
|
private CapsuleCollider2D cc;
|
|
private SpriteRenderer sr;
|
|
|
|
void Start()
|
|
{
|
|
rb = GetComponent<Rigidbody2D>();
|
|
cc = GetComponent<CapsuleCollider2D>();
|
|
sr = GetComponent<SpriteRenderer>();
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate()
|
|
{
|
|
rb.velocity = new Vector2(maxSpeed, rb.velocity.y);
|
|
}
|
|
|
|
void OnTriggerEnter2D(Collider2D cc)
|
|
{
|
|
if (!cc.gameObject.CompareTag("Player"))
|
|
{
|
|
maxSpeed = -maxSpeed;
|
|
sr.flipX = !sr.flipX;
|
|
}
|
|
}
|
|
}
|