Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class WateringCan : MonoBehaviour
- {
- [SerializeField]
- private ParticleSystem waterParticle;
- [SerializeField]
- private float waterRadius;
- private void Start()
- {
- waterParticle.gameObject.SetActive(false);
- //waterParticle.Stop();
- }
- void Update()
- {
- if (Input.GetButtonDown("Water"))
- {
- Seed[] seeds = FindObjectsOfType<Seed>();
- waterParticle.gameObject.SetActive(true);
- waterParticle.Play();
- Debug.Log("Water On!");
- foreach (Seed seed in seeds)
- {
- Debug.DrawLine(seed.transform.position, gameObject.transform.position, Color.blue, 2);
- float dist = Vector3.Distance(seed.transform.position, gameObject.transform.position);
- if (dist < waterRadius)
- {
- seed.Water();
- Debug.Log("Pouring water...");
- }
- }
- }
- if (Input.GetButtonUp("Water"))
- {
- waterParticle.Stop();
- }
- }
- private void OnDrawGizmos()
- {
- Gizmos.color = Color.cyan;
- Gizmos.DrawWireSphere(transform.position, waterRadius);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement