-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnemyCacatac.cs
28 lines (24 loc) · 911 Bytes
/
EnemyCacatac.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyCacatac : MonoBehaviour
{
int i=0;
float direction = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Time.timeScale == 1f && !GetComponent<Enemy>().GetIsFrozen())
{
if (GetComponent<BoxCollider2D>().IsTouchingLayers(LayerMask.GetMask("Ground"))) {GetComponent<Rigidbody2D>().gravityScale = 0f; GetComponent<Rigidbody2D>().velocity = new Vector2(0f, 0f); }
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 0.9f, LayerMask.GetMask("Ground"));
if (hit.collider == null || i == 300) { i = 0; direction *= -1; }
i++;
transform.position += new Vector3(direction * 0.01f, 0f, 0f);
}
}
}