-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttractorBalance.cs
54 lines (48 loc) · 1.31 KB
/
AttractorBalance.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
using UnityEngine;
using System.Collections;
public class AttractorBalance : MonoBehaviour {
public bool Gset = true;
public Vector2 MagnetizePos;
private Rigidbody2D CharRig;
// Use this for initialization
void Start ()
{
CharRig = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate ()
{
if (!Gset)
{
CharRig.AddForce(((MagnetizePos - CharRig.position)/4) , ForceMode2D.Impulse);
CharRig.velocity *= 0.925f;
}
}
public void ChangeMags()
{
GameObject[] GO =
GameObject.FindGameObjectsWithTag("Attractor_tag");
MagnetizePos = Vector2.zero;
if (GO.Length > 0)
{
int j = 0;
foreach (GameObject i in GO)
{
i.transform.rotation = Quaternion.identity;
j++;
MagnetizePos += new Vector2(i.transform.position.x, i.transform.position.y);
}
MagnetizePos /= j;
if (Gset)
{
CharRig.gravityScale = 0;
Gset = false;
}
}
else if (!Gset)
{
CharRig.gravityScale = 1;
Gset = true;
}
}
}