-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cs
109 lines (86 loc) · 2.91 KB
/
Enemy.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : EnemyBasics
{
[SerializeField] private LayerMask isGround;
public Collider2D coll;
private float jumpLenght = 5f;
private float jumpHeight = 5f;
private float leftCap = 34.9f;
private float rightCap = 51.82f;
//private float jumpForce = 2;
private bool facingLeft = true;
protected override void Start() //kendi start fonksiyonumuz oldu
{
base.Start(); //alıp kendinin gibi kullanıyor miras muabbeti. Diğer Start fonk. değiştirisen bu da değişir
coll = GetComponent<Collider2D>();
}
private void Update()
{
//zıplama animasyonundan sonra iniş animasyonu için gerekli
if (anim.GetBool("Jumping"))
{
if (rbEnemy.velocity.y < .1)
{
anim.SetBool("Falling", true);
anim.SetBool("Jumping", false);
}
}
if (coll.IsTouchingLayers(isGround) && anim.GetBool("Falling"))
{
anim.SetBool("Falling", false);
}
}
private void MoveEnemy()
{
if (facingLeft)
{
// leftcap'dan buyuk mu die bakıyoruz
if (transform.position.x > leftCap)
{
// Enemy'nin doğru yere baktığından emin ol değilse düzelt
if (transform.localScale.x != 1)
{
transform.localScale = new Vector3(1, 1);
}
// frog yerdeyse zıplasın test et
if (coll.IsTouchingLayers(isGround))
{
rbEnemy.velocity = new Vector2(-jumpLenght, jumpHeight);
anim.SetBool("Jumping", true);
//rbEnemy.AddForce(new Vector2(jumpLenght,jumpHeight)*jumpForce,ForceMode2D.Impulse);
}
}
//eğer değilse sağa döneeğiz
else
{
facingLeft = false;
}
}
else
{
// leftcap'dan buyuk mu die bakıyoruz
if (transform.position.x < rightCap)
{
// Enemy'nin doğru yere baktığından emin ol değilse düzelt
if (transform.localScale.x != -1)
{
transform.localScale = new Vector3(-1, 1);
}
// frog yerdeyse zıplasın test et
if (coll.IsTouchingLayers(isGround))
{
rbEnemy.velocity = new Vector2(jumpLenght, jumpHeight);
anim.SetBool("Jumping", true);
//rbEnemy.AddForce(new Vector2(-jumpLenght,jumpHeight)*jumpForce,ForceMode2D.Impulse);
}
}
//eğer değilse sağa döneeğiz
else
{
facingLeft = true;
}
}
}
}