-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGravityComponent.cs
44 lines (39 loc) · 1.1 KB
/
GravityComponent.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
namespace GravityMod;
public class GravityComponent : MonoBehaviour
{
private Rigidbody2D rb2d;
private bool isEnemy;
private bool hasDamage;
private int count;
public void Start()
{
rb2d = gameObject.GetComponent<Rigidbody2D>();
isEnemy = (gameObject.GetComponent<HealthManager>() != null);
hasDamage = (gameObject.GetComponent<DamageHero>() != null);
if (rb2d.bodyType == RigidbodyType2D.Static && !hasDamage)
{
enabled = false;
}
if (!isEnemy && !hasDamage)
{
enabled = false;
}
}
public void FixedUpdate()
{
count++;
if (count > 30)
{
count = 0;
rb2d.bodyType = RigidbodyType2D.Dynamic;
rb2d.isKinematic = false;
rb2d.freezeRotation = false;
rb2d.gravityScale = 1.75f;
Collider2D[] components = gameObject.GetComponents<Collider2D>();
for (int i = 0; i < components.Length; i++)
{
components[i].isTrigger = false;
}
}
}
}