Exemple #1
0
 private void Swing(Collider2D col)
 {
     if (col.tag == "Tree")
     {
         TreeController cTree = col.gameObject.GetComponent <TreeController>();
         cTree.DamageTree(swingDmg);
         Debug.Log("Tree hit for " + swingDmg);
     }
     else if (col.tag == "Bush")
     {
         BushController cBush = col.gameObject.GetComponent <BushController>();
         cBush.DamageBush(swingDmg);
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        spriteRenderer = GetComponent <SpriteRenderer>();

        Ballista         = GetComponent <Ballista>();
        Bat              = GetComponent <BatController>();
        BoundTrap        = GetComponent <BoundTrapController>();
        Bush             = GetComponent <BushController>();
        Button           = GetComponent <ButtonController>();
        Crocodile        = GetComponent <CrocodileController>();
        Drop             = GetComponent <DropController>();
        FallingPlataform = GetComponent <FallingPlataform>();
        //Pajaro = GameObject.FindGameObjectsWithTag("").GetComponent<ButtonController>();
        Mole       = GetComponent <MoloController>();
        Mushroom   = GetComponent <MushroomController>();
        Rat        = GetComponent <RatController>();
        Rock       = GetComponent <RockController>();
        RotateTrap = GetComponent <RotateTrapController>();
        Spawner    = GetComponent <Spawner>();
        Spikes     = GetComponent <SpikesController>();
        Thorms     = GetComponent <ThormsController>();
        Trap       = GetComponent <TrapController>();

        spriteRenderer.enabled = false;
        //Ballista.enabled = false;
        Bat.enabled              = false;
        BoundTrap.enabled        = false;
        Bush.enabled             = false;
        Button.enabled           = false;
        Crocodile.enabled        = false;
        Drop.enabled             = false;
        FallingPlataform.enabled = false;
        //Pajaro.enabled = false;
        Mole.enabled       = false;
        Mushroom.enabled   = false;
        Rat.enabled        = false;
        Rock.enabled       = false;
        RotateTrap.enabled = false;
        Spawner.enabled    = false;
        Spikes.enabled     = false;
        Thorms.enabled     = false;
        Trap.enabled       = false;
    }
Exemple #3
0
    void Update()
    {
        RaycastHit hit;
        Vector3    fwd = transform.TransformDirection(Vector3.forward);

        if (Physics.Raycast(transform.position, fwd, out hit, range, myLayerMask))
        {
            //TREE RAYCAST
            if (hit.collider.gameObject.tag == "Tree")
            {
                GameObject tree = (hit.collider.gameObject);

                if (Input.GetButtonDown("Fire1") && inv.items[15].item >= 1 && inv.equipables[0].activeSelf && timeStamp <= Time.time)
                {
                    inv.items[15].item--;
                    timeStamp     = Time.time + 1f;
                    audioSrc.clip = otherClip[0];
                    audioSrc.Play();
                    axeAnim.Play();
                    tree.GetComponent <TreeController>().health--;
                    inv.xp++;
                }
            }

            //STONE RAYCAST
            if (hit.collider.gameObject.tag == "Stone")
            {
                GameObject stone = (hit.collider.gameObject);

                if (Input.GetButtonDown("Fire1") && inv.items[16].item >= 1 && inv.equipables[1].activeSelf && timeStamp <= Time.time)
                {
                    //Object eff = Instantiate(effect, hit.point, Quaternion.LookRotation(hit.normal));
                    //Destroy(eff, 0.25f);
                    inv.items[16].item--;
                    timeStamp     = Time.time + 1f;
                    audioSrc.clip = otherClip[0];
                    audioSrc.Play();
                    pickaxeAnim.Play();
                    stone.GetComponent <StoneController>().health--;
                    inv.xp++;
                }
            }

            /*
             * //BUILDING RAYCAST
             * else if (hit.collider.gameObject.tag == "Building")
             * {
             *
             *  if (Input.GetButtonDown("Fire1") && currentMiningLevel >= 1)
             *  {
             *      //building.GetComponent<BuildingController>().health--;
             *  }
             * }
             */

            //CAMPFIRE RAYCAST
            else if (hit.collider.gameObject.tag == "Campfire")
            {
                infoText.gameObject.SetActive(true);
                infoText.text = "Open/Close Campfire";

                if (Input.GetKeyDown(KeyCode.E))
                {
                    inv.OpenCampfire();
                }
            }

            //SLEEP RAYCAST
            else if (hit.collider.gameObject.tag == "Sleep")
            {
                infoText.gameObject.SetActive(true);
                infoText.text = "Sleep";

                if (Input.GetButtonDown("Open"))
                {
                    statsScript.Sleep();
                }
            }

            //CRAFTING TABLE RAYCAST
            else if (hit.collider.gameObject.tag == "CraftingTable")
            {
                infoText.gameObject.SetActive(true);
                infoText.text = "Open/Close Crafting Table";

                if (Input.GetButtonDown("Open"))
                {
                    inv.OpenCraftingTable();
                }
            }

            //BUSH RAYCAST
            else if (hit.collider.gameObject.tag == "Berry")
            {
                GameObject     bush       = (hit.collider.gameObject);
                BushController bushScript = bush.GetComponent <BushController>();
                if (bushScript.isMature)
                {
                    infoText.gameObject.SetActive(true);
                    infoText.text = "Pick Berries";
                }

                if (Input.GetButtonDown("Open"))
                {
                    bushScript.Pick();
                }
            }

            //ITEM RAYCAST
            else if (hit.collider.gameObject.tag == "Item")
            {
                GameObject item = (hit.collider.gameObject);
                infoText.gameObject.SetActive(true);
                infoText.text = "Pick Up <i>" + item.name + "</i>";

                if (Input.GetButtonDown("Pickup"))
                {
                    ItemController itemScript = item.GetComponent <ItemController>();
                    itemScript.PickUp();
                    StartCoroutine(Notifications.Call("Picked Up <i>" + item.name + "</i>!"));
                    audioSrc.clip = otherClip[1];
                    audioSrc.Play();
                }
            }

            /*
             * //CHEST RAYCAST
             * else if (hit.collider.gameObject.tag == "Chest")
             * {
             *  GameObject item = (hit.collider.gameObject);
             *  infoText.gameObject.SetActive(true);
             *  infoText.text = "Open/Close Chest";
             *
             *  if (Input.GetButtonDown("Open"))
             *  {
             *      //inv.OpenChest();
             *  }
             * }
             */

            else
            {
                infoText.gameObject.SetActive(false);
            }
        }
        else
        {
            infoText.gameObject.SetActive(false);
        }
    }
Exemple #4
0
 public static void CutBush(BushController bush)
 {
     bush.stats.Health = 100;
     bush.gameObject.SetActive(false);
 }