Рандомное телепортирование ботов и игрока при соприкосновении, Как исправить?
07.06.2020, 16:55. Показов 429. Ответов 1
Помогите пожалуйста
код бота
| C# | 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
| using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Bot : MonoBehaviour
{
private float waitTime;
public float startWaitTime;
public GameObject[] moveSpots;
// public Transform[] moveSpots;
private int randomSpot;
//Vector2 mousePosition;
private float quotient;
private float delta;
public float mass;
private Vector2 ranVec;
private Vector3 vecScale;
// public Camera cam;
// private float camSize;
private int massCoin;
private int massCoin1;
private int massCoin2;
private int massCoin3;
private int massCoin4;
private int massCoin5;
private int massCoin6;
// public Text MyText;
private Vector2 randVector;
void Awake()
{
}
public class Example
{
void Start()
{
// Make the game run as fast as possible
Application.targetFrameRate = 300;
}
}
void Start()
{
mass = 500;
delta = 3;
vecScale.Set(1, 1, 1);
//delta = 8 * Mathf.Pow(20, -Mathf.Log(2, 01.1f)) * Mathf.Pow(mass, Mathf.Log(2, 0.1f));
//camSize = 7;
massCoin = 3;
massCoin1 = 4;
massCoin2 = 5;
massCoin3 = 6;
massCoin4 = 5;
massCoin5 = 4;
massCoin6 = 3;
waitTime = startWaitTime;
randomSpot = Random.Range(0, moveSpots.Length);
moveSpots = GameObject.FindGameObjectsWithTag("MoveSpot");
// ms = GameObject.FindGameObjectsWithTag("MoveSpot");
}
// Update is called once per frame
void Update()
{
// delta = 8 * Mathf.Pow(20, -Mathf.Log(2, 0.1f)) * Mathf.Pow(mass, Mathf.Log(2, 0.1f));
// mousePosition = Input.mousePosition;
// mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
// mousePosition -= (Vector2)transform.position;
//quotient = Mathf.Sqrt(mousePosition.x * mousePosition.x + mousePosition.y * mousePosition.y) / delta;
// mousePosition /= quotient;
//transform.Translate(mousePosition * Time.deltaTime);
vecScale.Set((mass / 200 + 0.95f), (mass / 200 + 0.95f), 1);
{
gameObject.transform.position = Vector2.MoveTowards(transform.position, moveSpots[randomSpot].gameObject.transform.position, delta * Time.deltaTime);
if (Vector2.Distance(transform.position, moveSpots[randomSpot].gameObject.transform.position) < 0.2f)
{
if (waitTime <= 0)
{
randomSpot = Random.Range(0, moveSpots.Length);
waitTime = startWaitTime;
}
else
{
waitTime -= Time.deltaTime;
}
}
}
transform.localScale = vecScale;
mass -= 0.00000002f * mass * mass;
// MyText.text = string.Format("{0}", mass);
if (50000 < mass)
{
// cam.orthographicSize = 150;
transform.localScale = new Vector3(250, 250, 1);
}
// else
// {
// if (cam.orthographicSize > camSize)
// {
// if (cam.orthographicSize - 0.2 > camSize)
// {
// cam.orthographicSize = camSize;
// }
// else
// {
// cam.orthographicSize -= 0.0001f;
// }
// }
// else if (cam.orthographicSize < camSize)
// {
// if (cam.orthographicSize + 0.2 < camSize)
// {
// cam.orthographicSize = camSize;
// }
// else
// {
// cam.orthographicSize += 0.0001f;
// }
}
// if (cam.orthographicSize < camSize)
// {
// if (cam.orthographicSize - 0.2 < camSize)
// {
// cam.orthographicSize = camSize;
// }
// else
// {
// cam.orthographicSize += 0.0001f;
// }
// }
// else if (cam.orthographicSize > camSize)
// {
// if (cam.orthographicSize - 0.2 < camSize)
// {
// cam.orthographicSize = camSize;
// }
// else
// {
// cam.orthographicSize -= 0.0001f;
// }
// }
// }
// }
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Eat")
{
mass += massCoin;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
// camSize += 0.002f * massCoin;
}
if (collision.gameObject.tag == "Eat1")
{
mass += massCoin1;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
// camSize += 0.002f * massCoin1;
}
if (collision.gameObject.tag == "Eat2")
{
mass += massCoin2;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
// camSize += 0.002f * massCoin2;
}
if (collision.gameObject.tag == "Eat3")
{
mass += massCoin3;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
// camSize += 0.002f * massCoin3;
}
if (collision.gameObject.tag == "Eat4")
{
mass += massCoin4;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
// camSize += 0.002f * massCoin4;
}
{
mass += massCoin5;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
// camSize += 0.002f * massCoin5;
}
{
mass += massCoin6;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
// camSize += 0.002f * massCoin6;
}
}
} |
|
код игрока
| C# | 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
| using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using GoogleMobileAds.Api;
public class Test : MonoBehaviour {
Vector2 mousePosition;
private float quotient;
private float delta;
public float mass;
private Vector2 ranVec;
private Vector3 vecScale;
public Camera cam;
private float camSize;
private int massCoin;
private int massCoin1;
private int massCoin2;
private int massCoin3;
private int massCoin4;
private int massCoin5;
private int massCoin6;
public Text MyText;
public class Example
{
void Start()
{
// Make the game run as fast as possible
Application.targetFrameRate = 300;
}
}
void Start () {
mass = 10;
delta = 3;
vecScale.Set(1, 1, 1);
delta = 8 * Mathf.Pow(20, -Mathf.Log(2, 01.1f)) * Mathf.Pow(mass, Mathf.Log(2, 0.1f));
camSize = 7;
massCoin = 3;
massCoin1 = 4;
massCoin2 = 5;
massCoin3 = 6;
massCoin4 = 5;
massCoin5 = 4;
massCoin6 = 3;
}
// Update is called once per frame
void Update () {
delta = 8 * Mathf.Pow(20, -Mathf.Log(2, 0.1f)) * Mathf.Pow(mass, Mathf.Log(2, 0.1f));
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
mousePosition -= (Vector2)transform.position;
quotient = Mathf.Sqrt(mousePosition.x * mousePosition.x + mousePosition.y * mousePosition.y) / delta;
mousePosition /= quotient;
transform.Translate(mousePosition * Time.deltaTime);
vecScale.Set((mass / 200 + 0.95f), (mass / 200 + 0.95f), 1);
transform.localScale = vecScale;
mass -= 0.00000002f * mass * mass;
MyText.text = string.Format("{0}", mass);
if (50000 < mass)
{
cam.orthographicSize = 150;
transform.localScale = new Vector3(250, 250, 1);
}
else
{
if (cam.orthographicSize > camSize)
{
if (cam.orthographicSize - 0.2 > camSize)
{
cam.orthographicSize = camSize;
}
else
{
cam.orthographicSize -= 0.0001f;
}
}
else if (cam.orthographicSize < camSize)
{
if (cam.orthographicSize + 0.2 < camSize)
{
cam.orthographicSize = camSize;
}
else
{
cam.orthographicSize += 0.0001f;
}
}
if (cam.orthographicSize < camSize)
{
if (cam.orthographicSize - 0.2 < camSize)
{
cam.orthographicSize = camSize;
}
else
{
cam.orthographicSize += 0.0001f;
}
}
else if (cam.orthographicSize > camSize)
{
if (cam.orthographicSize - 0.2 < camSize)
{
cam.orthographicSize = camSize;
}
else
{
cam.orthographicSize -= 0.0001f;
}
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Eat")
{
mass += massCoin;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
camSize += 0.002f * massCoin;
}
if (collision.gameObject.tag == "Eat1")
{
mass += massCoin1;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
camSize += 0.002f * massCoin1;
}
if (collision.gameObject.tag == "Eat2")
{
mass += massCoin2;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
camSize += 0.002f * massCoin2;
}
if (collision.gameObject.tag == "Eat3")
{
mass += massCoin3;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
camSize += 0.002f * massCoin3;
}
if (collision.gameObject.tag == "Eat4")
{
mass += massCoin4;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
camSize += 0.002f * massCoin4;
}
{
mass += massCoin5;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
camSize += 0.002f * massCoin5;
}
{
mass += massCoin6;
ranVec.Set(Random.Range(-249.5f, 249.5f), Random.Range(-249.5f, 249.5f));
collision.gameObject.transform.position = ranVec;
camSize += 0.002f * massCoin6;
}
}
} |
|
0
|