private void Update()
    {
        if (Input.GetButton("Drop"))
        {
            if (!_handSpotFree)
            {
                DropCurrentItem(_pickedItem);
            }
        }

        if (Input.GetButton("Pickup") && !_pickUpLock)
        {
            _pickUpLock = true;
            Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 2, _pickUpLayer))
            {
                GameObject hitGameObject = hit.collider.gameObject;
                hitGameObject.GetComponent <Collider>().enabled = false;
                PickUpItem(hitGameObject);
            }
            else if (Physics.Raycast(ray, out hit, 2, _plantLayer))
            {
                GameObject hitGameObject = hit.collider.gameObject;
                hitGameObject.GetComponent <Collider>().enabled = false;
                PickUpItem(hitGameObject);
            }

            _pickUpLock = false;
        }
        if (Input.GetButton("Use") && !_useLock)
        {
            _useLock = true;
            Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 3, _seedSpotLayer))
            {
                SeedSpot seedSpot = hit.collider.gameObject.GetComponent <SeedSpot>();
                if (_pickedItem.GetComponent <PickUpItem>().GetPickUpItemType() == PickUpItemType.Seed && seedSpot.GetSpotFree() && !_pickedItem.GetComponent <Plant>().GetBeenPlaced())
                {
                    _pickedItem.GetComponent <Plant>().SetBeenPlaced(true);
                    seedSpot.PlantPlantSeed(_pickedItem);
                    _seedSpotManager.AddSeedSpotsToActiveSeedSpotsList(seedSpot);
                    _handSpotFree = true;
                }
            }
            else if (Physics.Raycast(ray, out hit, 3, _interactableButtonLayer))
            {
                if (_seedSpotManager.SeedSpotsNotEmpty())
                {
                    _seedSpotManager.WaterPlants();
                    _waveManager.LaunchWave();
                }
            }
            _useLock = false;
        }
    }
Exemple #2
0
 public void AddSeedSpotsToActiveSeedSpotsList(SeedSpot activatedSeedSpot)
 {
     if (!(_activeSeedSpots.Contains(activatedSeedSpot.gameObject)))
     {
         _activeSeedSpots.Add(activatedSeedSpot.gameObject);
         activatedSeedSpot.GetComponentInChildren <ParticleSystem>().Stop();
         _nonActiveSeedSpots.Remove(activatedSeedSpot.gameObject);
     }
 }
Exemple #3
0
 public void RemoveSeedSpotsFromActiveSeedSpotList(SeedSpot deactivatedSeedSpot)
 {
     if (!(_nonActiveSeedSpots.Contains(deactivatedSeedSpot.gameObject)))
     {
         deactivatedSeedSpot.SetSpotFree();
         _nonActiveSeedSpots.Add(deactivatedSeedSpot.gameObject);
         deactivatedSeedSpot.GetComponentInChildren <ParticleSystem>().Play();
         _activeSeedSpots.Remove(deactivatedSeedSpot.gameObject);
     }
 }
Exemple #4
0
    private IEnumerator EnemyAttackRoutine(SeedSpot g)
    {
        while (g.gameObject.GetComponentInChildren <Plant>() != null)
        {
            yield return(new WaitForSeconds(_attackDelay));

            _animator.SetTrigger("attack");
            if (g.gameObject.GetComponentInChildren <Plant>() != null)
            {
                g.gameObject.GetComponentInChildren <Plant>().DecreaseHealth(_attackDamage);
            }
            else
            {
                yield return(null);
            }
            _animator.SetTrigger("idle");
            if (!(g.gameObject.GetComponentInChildren <Plant>() != null))
            {
                yield return(null);
            }
        }
    }