Coin.cs 980 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class Coin : BaseBehaviour
  5. {
  6. private void Start()
  7. {
  8. }
  9. private void Update()
  10. {
  11. }
  12. public IEnumerator GenerateCoinCoroutine(float randomRange, Vector3 position, int count, int coinValue)
  13. {
  14. for (int i = 0; i < count; i++)
  15. {
  16. GameObject obj = UnityEngine.Object.Instantiate<GameObject>(this.coin, position + new Vector3(0f, 2f), Quaternion.Euler(Vector3.zero));
  17. obj.GetComponent<RedMoney>().coinValue = coinValue;
  18. obj.GetComponent<Rigidbody2D>().gravityScale = 0.8f;
  19. obj.GetComponent<Rigidbody2D>().velocity = new Vector2(UnityEngine.Random.Range(-randomRange, randomRange), 17f);
  20. yield return new WaitForSeconds(0.05f);
  21. }
  22. yield break;
  23. }
  24. public void GenerateCoin(float randomRange, int count, int coinValue)
  25. {
  26. base.StartCoroutine(this.GenerateCoinCoroutine(randomRange, base.transform.position, count, coinValue));
  27. }
  28. public GameObject coin;
  29. }