LootScript.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public enum LootType { SC = 0, HC = 1, Energy = 2, Level = 3 }
  5. public class LootScript : Clickable
  6. {
  7. public LootType Type;
  8. public int Value;
  9. public Sprite[] Sprites;
  10. // Use this for initialization
  11. void Start()
  12. {
  13. GetComponent<SpriteRenderer>().sprite = Sprites[(int)Type];
  14. Vector2 dir = new Vector2(-Random.Range(0.1f, 0.9f),
  15. Random.Range(0.1f, 0.9f)).normalized;
  16. float power = Random.Range(100, 200);
  17. GetComponent<Rigidbody2D>().AddForce(dir * power);
  18. Invoke("Collect", 6);
  19. }
  20. // Update is called once per frame
  21. void Update()
  22. {
  23. }
  24. public override void DoSomething()
  25. {
  26. base.DoSomething();
  27. Collect();
  28. }
  29. public void Collect()
  30. {
  31. switch (Type)
  32. {
  33. case LootType.SC:
  34. GameManager.Instance.AddSoftCurrency(Value);
  35. break;
  36. case LootType.HC:
  37. GameManager.Instance.AddHardCurrency(Value);
  38. break;
  39. case LootType.Energy:
  40. GameManager.Instance.IncrementMotivation(Value,false);
  41. break;
  42. case LootType.Level:
  43. GameManager.Instance.IncrementExperience(Value);
  44. break;
  45. default:
  46. break;
  47. }
  48. Destroy(gameObject);
  49. }
  50. }