Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class WateringCan : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private ParticleSystem waterParticle;
  9.  
  10. [SerializeField]
  11. private float waterRadius;
  12.  
  13. private void Start()
  14. {
  15. waterParticle.gameObject.SetActive(false);
  16. //waterParticle.Stop();
  17. }
  18.  
  19. void Update()
  20. {
  21. if (Input.GetButtonDown("Water"))
  22. {
  23. Seed[] seeds = FindObjectsOfType<Seed>();
  24.  
  25. waterParticle.gameObject.SetActive(true);
  26. waterParticle.Play();
  27. Debug.Log("Water On!");
  28.  
  29. foreach (Seed seed in seeds)
  30. {
  31. Debug.DrawLine(seed.transform.position, gameObject.transform.position, Color.blue, 2);
  32. float dist = Vector3.Distance(seed.transform.position, gameObject.transform.position);
  33.  
  34. if (dist < waterRadius)
  35. {
  36. seed.Water();
  37. Debug.Log("Pouring water...");
  38. }
  39. }
  40. }
  41.  
  42. if (Input.GetButtonUp("Water"))
  43. {
  44. waterParticle.Stop();
  45. }
  46. }
  47.  
  48. private void OnDrawGizmos()
  49. {
  50. Gizmos.color = Color.cyan;
  51. Gizmos.DrawWireSphere(transform.position, waterRadius);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement