ObjectNames
How do I use Object Names
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonTransformViewEditor.cs
Copy
220 private void DrawPropertyWithHelpIcon(ref Rect propertyRect, ref bool isHelpOpen, SerializedProperty property, string tooltip)
221 {
222 Rect propertyFieldRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width - 20, propertyRect.height);
223 string propertyName = ObjectNames.NicifyVariableName(property.name);
224 EditorGUI.PropertyField(propertyFieldRect, property, new GUIContent(propertyName, tooltip));
225
226 Rect helpIconRect = new Rect(propertyFieldRect.xMax + 5, propertyFieldRect.yMin, 20, propertyFieldRect.height);
227 isHelpOpen = GUI.Toggle(helpIconRect, isHelpOpen, PhotonGUI.HelpIcon, GUIStyle.none);
228
229 propertyRect.y += EDITOR_LINE_HEIGHT;
230 }
File name: Animal.cs
Copy
300 public void OnCollisionEnter2D(Collision2D otherCollision)
301 {
302 if (otherCollision.gameObject.name == MapObjectNames.GroundObject)
303 {
304 state = RUN;
305 stepJump = 2;
306 isSprings = false;
307 }
308 else if (otherCollision.gameObject.name == "Bullet")
309 {
310 if (gameObject.GetComponent
311 if (animalIndex != otherCollision.gameObject.GetComponent
312 {
313 if (otherCollision.gameObject.GetComponent
314 {
315 if (otherCollision.gameObject.GetComponent
316 {
317 gameScreen.addScore(10, gameObject.transform.localPosition);
318 gameScreen.setCombo(1, otherCollision.gameObject.GetComponent
319 }
320 gameScreen.AnimalcollisionWithBullet(gameObject, otherCollision.gameObject);
321 }
322 }
323 }
324 }
File name: Animal.cs
Copy
326 public void OnTriggerEnter2D(Collider2D otherCollider)
327 {
328 string mapObjectName = otherCollider.gameObject.name;
329
330 if (mapObjectName == MapObjectNames.MarkObject && animalIndex != 0)
331 {
332 int r = Random.Range(0, 2);
333 if (r == 0)
334 if (!isBooster && !isSprings)
335 Jump();
336 }
337 else if (mapObjectName == MapObjectNames.HoleObject && animalIndex != 0)
338 {
339 Jump();
340 }
341 else if (mapObjectName == MapObjectNames.BoostObject)
342 {
343 booster();
344 stepJump = 2;
345 if (animalIndex == 0)
346 {
347 gameScreen.setCombo(6);
348 gameScreen.addScore(5, transform.localPosition);
349 }
350 }
351 else if (mapObjectName == MapObjectNames.SpringsObject)
352 {
353 springs();
354 stepJump = 2;
355 if (animalIndex == 0)
356 {
357 gameScreen.setCombo(7);
358 gameScreen.addScore(5, transform.localPosition);
359 }
360 }
361 else if (mapObjectName == MapObjectNames.RevivalObject)
362 {
363 setRevivalPosition(otherCollider.gameObject.GetComponent
364 }
365 else if (mapObjectName == MapObjectNames.DeadLine)
366 {
367 if (animalIndex == 0)
368 {
369 gameScreen.showRevivalTask(2, EmotionType.BUON);
370 }
371 isRevival = true;
372 setStand(false, 0, STATE_RUN);
373 IsProtected = false;
374 revivalTime = 2;
375 }
376 else if (mapObjectName == MapObjectNames.SkillObject)
377 {
378 gameScreen.eatSkillRandom(otherCollider.gameObject.GetComponent
379 otherCollider.gameObject.transform.localPosition, animalIndex);
380 if (animalIndex == 0)
381 SoundManager.playSound("Sounds/anskill");
382
383 }
384 else if (mapObjectName == MapObjectNames.FinishObject && animalIndex == 0)
385 {
386 gameScreen.finishGame();
387
388 Destroy(otherCollider);//cho nay de tranh lap lai nhieu lan ham finishgame
389 }
390 else if (mapObjectName == MapObjectNames.Bullet)
391 {
392 if (animalIndex != otherCollider.gameObject.GetComponent
393 {
394 if (IsProtected) return;
395 gameScreen.AnimalcollisionWithBullet(gameObject, otherCollider.gameObject);
396 isSprings = false;
397 isBooster = false;
398
399 if (otherCollider.gameObject.GetComponent
400 {
401 gameScreen.addScore(10, gameObject.transform.localPosition);
402 gameScreen.setCombo(1, otherCollider.gameObject.GetComponent
403 }
404 else
405 {
406 gameScreen.setCombo(-1);
407 }
408 }
409 }
410 else if (otherCollider.gameObject.name == MapObjectNames.Coin && animalIndex == 0)//if is player
411 {
412 gameScreen.addDurtGold(otherCollider.gameObject.transform.localPosition);
413 Destroy(otherCollider.gameObject);
414 gameScreen.m_gold++;
415 SoundManager.playSound("Sounds/anxu");
416 }
417 }
File name: Animal.cs
Copy
419 public void OnCollisionExit2D(Collision2D otherCollision)
420 {
421 if (otherCollision.gameObject.name == MapObjectNames.GroundObject)
422 {
423 if (state == RUN)
424 {
425 state = JUMPING;
426 }
427 }
428 }
File name: Bullet.cs
Copy
71 public void OnTriggerEnter2D(Collider2D otherCollider)
72 {
73 if (otherCollider.gameObject.name == MapObjectNames.DeadLine)
74 {
75 Destroy(gameObject);
76 }
77 else if (otherCollider.gameObject.name == MapObjectNames.FinishObject)
78 {
79 Destroy(gameObject);
80 }
81 }
File name: GameScreen.cs
Copy
150 private void setupMap(GameObject mObject)
151 {
152 GameObject markGounds = new GameObject("MarkGrounds");
153 markGounds.transform.parent = mObject.transform;
154 markGounds.transform.localScale = new Vector3(1, 1, 1);
155 markGounds.transform.localPosition = new Vector3(0, 0, 0);
156
157 for (int i = 0; i < mObject.transform.childCount; i++)
158 {
159 Transform childTransform = mObject.transform.GetChild(i);
160 string childname = childTransform.gameObject.name;
161 if (childname == MapObjectNames.MarkObject)
162 {
163 createMarkObjects(childTransform);
164 }
165 else if (childname == MapObjectNames.BoostObject)
166 {
167 createBoosterObjects(childTransform);
168 }
169 else if (childname == MapObjectNames.SpringsObject)
170 {
171 createSpringsObjects(childTransform);
172 }
173 else if (childname == MapObjectNames.HoleObject)
174 {
175 createHoles(childTransform);
176 }
177 else if (childname == MapObjectNames.Coin)
178 {
179 createCoins(childTransform);
180 }
181 else if (childname == MapObjectNames.SkillObject)
182 {
183 createSkillRandoms(childTransform);
184 }
185 else if (childname == MapObjectNames.RevivalObject)
186 {
187 createRevivalObjects(childTransform);
188 }
189 else if (childname == MapObjectNames.GroundObject)
190 {
191 createGrounds(childTransform, markGounds.transform);
192 }
193 else if (childname == MapObjectNames.FinishObject)
194 {
195 createFinishObject(childTransform);
196 }
197 }
198
199 createDeadLine();
200 }
File name: GameScreen.cs
Copy
202 private void createMarkObjects(Transform parentTransform)
203 {
204 for (int i = 0; i < parentTransform.childCount; i++)
205 {
206 GameObject markObject = parentTransform.GetChild(i).gameObject;
207 markObject.name = MapObjectNames.MarkObject;
208 if (markObject.GetComponent
209 Destroy(markObject.GetComponent
210 BoxCollider2D childCollider = markObject.AddComponent
211 childCollider.size = new Vector2(20, 1000);
212 childCollider.isTrigger = true;
213 }
214 }
File name: GameScreen.cs
Copy
216 private void createBoosterObjects(Transform parentTransform)
217 {
218 for (int i = 0; i < parentTransform.childCount; i++)
219 {
220 GameObject boosterObject = (GameObject)Instantiate(Resources.Load
221 GameObject c = parentTransform.GetChild(i).gameObject;
222 boosterObject.transform.position = c.transform.position;
223 boosterObject.transform.localScale = new Vector3(1, 1, 0);
224 boosterObject.transform.parent = boosterLayer.transform;
225 BoxCollider2D childCollider = boosterObject.AddComponent
226 childCollider.size = new Vector2(0.9f, 0.2f);
227 childCollider.isTrigger = true;
228 boosterObject.transform.position -= new Vector3(-0.45f, 0.1f, 0);
229 boosterObject.name = MapObjectNames.BoostObject;
230
231 Destroy(c);
232 }
233 }
File name: GameScreen.cs
Copy
235 private void createSpringsObjects(Transform parentTransform)
236 {
237 for (int i = 0; i < parentTransform.childCount; i++)
238 {
239 GameObject springsObject = (GameObject)Instantiate(Resources.Load
240 GameObject c = parentTransform.GetChild(i).gameObject;
241 springsObject.transform.position = c.transform.position;
242 springsObject.transform.parent = springsLayer.transform;
243 springsObject.transform.position -= new Vector3(-0.2f, 0.3f, 0);
244 springsObject.name = MapObjectNames.SpringsObject;
245 Destroy(c);
246 }
247 }
File name: GameScreen.cs
Copy
249 private void createHoles(Transform parentTransform)
250 {
251 for (int i = 0; i < parentTransform.childCount; i++)
252 {
253 BoxCollider2D childCollider = parentTransform.GetChild(i).gameObject.GetComponent
254 childCollider.isTrigger = true;
255 parentTransform.GetChild(i).gameObject.name = MapObjectNames.HoleObject;
256 }
257 }
Download file with original file name:ObjectNames
ObjectNames 154 lượt xem
Gõ tìm kiếm nhanh...