Example #1
0
    public void Interact()
    {
        if (Holding == null)
        {
            //GameObject ItemDistanceCheck;
            //ItemDistanceCheck = transform.GetChild(0).GetComponent<InteractHitBox>().GetItem();

            if (transform.GetChild(0).GetComponent <InteractHitBox>().Item.Count != 0)
            {
                CheckforItemsinHitbox();
            }

            else if (Dispenser != null)
            {
                Vector3 SpawnPoint;
                SpawnPoint = (transform.position + new Vector3(0.2f * Dir, 0.7f));

                if (Dispenser.tag == "seeddispenser")
                {
                    Holding = Instantiate(Dispenser.GetComponent <SeedDispenser>().Seed, SpawnPoint, Quaternion.identity);
                }

                if (Dispenser.tag == "waterdispenser")
                {
                    Holding = Dispenser.GetComponent <WaterPumpScript>().Pump(gameObject, SpawnPoint);

                    //Holding = Instantiate(Dispenser.GetComponent<WaterPumpScript>().WaterBag, SpawnPoint, Quaternion.identity);
                }

                if (Dispenser.tag == "fertilizerdispenser")
                {
                    Holding = Instantiate(Dispenser.GetComponent <FertilizerDispenser>().Fertilizer, SpawnPoint, Quaternion.identity);
                }
            }

            //FOR WHEN THE BURROW HAS AN INCOMPLETE TIMER

            else if (Burrow != null && Burrow.GetComponent <BurrowInteractTimer>().SeedType != null)
            {
                Debug.Log("Working on Planted Burrow");
                GameObject BurrowSeedType;
                BurrowSeedType = Burrow.GetComponent <BurrowInteractTimer>().SeedType;

                Burrow.GetComponent <BurrowInteractTimer>().TimerStart(gameObject, BurrowSeedType);
            }
        }
        else if (Holding != null)
        {
            //TO PLANT SEEDS
            if (Holding.tag == "seed" && Burrow != null && Burrow.GetComponent <BurrowBehavior>().readyToPlant)
            {
                if (transform.GetChild(0).GetComponent <InteractHitBox>().PlantedGhost != null)
                {
                    Destroy(transform.GetChild(0).GetComponent <InteractHitBox>().PlantedGhost);
                }
                PlantSeed(Holding, Burrow);
            }
            //TO DROP ITEMS
            else
            {
                GameObject TempHold;
                TempHold = Holding;
                //Holding.GetComponent<Rigidbody2D>().isKinematic = false;
                ThrowTurnOffKinTurnOnCol();
                Holding = null;
                //if(TempHold.GetComponent<SeedScript>().collided == true)
                //    TempHold.transform.position += new Vector3(0, transform.position.y)
            }
        }
    }