aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/Flyer.cs
blob: dfb5f2ed0e29a6738ce42407a2704de95f786ecb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Flyer : MonoBehaviour {
  public Vector2 velocity = new Vector2(1, 0);

  private Rigidbody2D body;

  void Start() {
    body = GetComponent<Rigidbody2D>();
    body.velocity = velocity;
  }

  void OnTriggerEnter2D(Collider2D other) {
    switch (other.gameObject.tag) {
      case "Platform":
        Flip();
        break;
    }
  }

  void OnTriggerStay2D(Collider2D other) {
    GameObject ogo = other.gameObject;
    switch (ogo.tag) {
      case "Player":
        CharacterControl cc = GetComponent<CharacterControl>();
        if (cc) cc.Damaged();
        break;
    }
  }

  void Flip() {
    body.velocity = -body.velocity;
  }

  void Update() {
    transform.localScale = new Vector2(Mathf.Sign(body.velocity.x), 1);
  }
}