-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlugController.cs
62 lines (47 loc) · 1.58 KB
/
SlugController.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SlugController : MonoBehaviour
{
[Header("Referências")]
public Transform enemie;
public Transform[] Position;
[Header("Configurações de Movimento")]
public float Speed = 2.5f;
public bool facingRight;
[Header("Componentes")]
private SpriteRenderer enemieSprite;
private int IdTarget;
// Start is called before the first frame update
void Start()
{
enemieSprite = enemie.gameObject.GetComponent<SpriteRenderer>();
enemie.position = Position[0].position;
IdTarget = 1;
}
// Update is called once per frame
void FixedUpdate()
{
if(enemie != null){
enemie.position = Vector3.MoveTowards(enemie.position, Position[IdTarget].position, Speed * Time.deltaTime);
if(enemie.position == Position[IdTarget].position){
IdTarget += 1;
if( IdTarget == Position.Length){
IdTarget = 0;
}
if(Position[IdTarget].position.x < enemie.position.x && facingRight){
Flip();
}
else if(Position[IdTarget].position.x > enemie.position.x && !facingRight){
Flip();
}
}
}
}
void Flip(){
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}