-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy2.cs
42 lines (30 loc) · 867 Bytes
/
Enemy2.cs
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
41
42
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy2 : MonoBehaviour
{
private Rigidbody2D rig;
private Animator anim;
public float speed;
public Transform rightCol;
public Transform leftCol;
public Transform headPoint;
private bool colliding;
public LayerMask layer;
void Start()
{
rig = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
rig.velocity = new Vector2(speed, rig.velocity.y);
colliding = Physics2D.Linecast(rightCol.position, leftCol.position);
if (colliding)
{
transform.localScale = new Vector2(transform.localScale.x * -1f, transform.localScale.y);
speed *= -1f;
Debug.Log("Enemy is colliding with vector");
}
}
}