// Update is called once per frame
 void Update()
 {
     coolDown -= Time.deltaTime;
     if (coolDown < 0)
     {
         coolDown = 0;
     }
     if (!PauseScreen.isPaused)   //BECAUSE UNITY BUG
     {
         if (Input.GetMouseButtonDown(0))
         {
             RaycastHit hit;
             if (Physics.Raycast(transform.position, transform.forward, out hit, distance) && coolDown <= 0)
             {
                 if (hit.collider.gameObject.tag == "Tree")
                 {
                     treeChop              = GameObject.Find(hit.collider.gameObject.name).GetComponent <TreeChop> ();
                     treeChop.currentWood -= 1;
                     inventory.wood       += 1;
                     PlayerPrefs.SetInt("Wood", inventory.wood + saveWood);
                     coolDown = maxCooldown;
                     if (treeChop.currentWood <= 0)
                     {
                         GameObject.Find(hit.collider.gameObject.name).SetActive(false);
                     }
                 }
                 else if (hit.collider.gameObject.tag == "Bush")
                 {
                     berryCollect = GameObject.Find(hit.collider.gameObject.name).GetComponent <BerryCollect> ();
                     berryCollect.currentBerry -= 1;
                     inventory.berries         += 1;
                     PlayerPrefs.SetInt("Berry", inventory.berries + saveBerries);
                     coolDown = maxCooldown;
                     if (berryCollect.currentBerry <= 0)
                     {
                         GameObject.Find(hit.collider.gameObject.name).SetActive(false);
                     }
                 }
                 else if (hit.collider.gameObject.tag == "Rock")
                 {
                     rockSmash              = GameObject.Find(hit.collider.gameObject.name).GetComponent <RockSmash> ();
                     rockSmash.currentRock -= 1;
                     inventory.rock        += 1;
                     PlayerPrefs.SetInt("Rock", inventory.rock + saveRock);
                     coolDown = maxCooldown;
                     if (rockSmash.currentRock <= 0)
                     {
                         GameObject.Find(hit.collider.gameObject.name).SetActive(false);
                     }
                 }
             }
         }
     }        // BECAUSE UNITY BUG
 }
 // Update is called once per frame
 void Update()
 {
     coolDown -= Time.deltaTime;
     if (coolDown < 0)
     {
         coolDown = 0;
     }
     if (!PauseScreen.isPaused) { //BECAUSE UNITY BUG
         if (Input.GetMouseButtonDown (0)) {
             RaycastHit hit;
             if (Physics.Raycast (transform.position, transform.forward, out hit, distance) && coolDown <= 0) {
                 if (hit.collider.gameObject.tag == "Tree") {
                     treeChop = GameObject.Find (hit.collider.gameObject.name).GetComponent<TreeChop> ();
                     treeChop.currentWood -= 1;
                     inventory.wood += 1;
                     PlayerPrefs.SetInt ("Wood", inventory.wood + saveWood);
                     coolDown = maxCooldown;
                     if (treeChop.currentWood <= 0) {
                         GameObject.Find (hit.collider.gameObject.name).SetActive (false);
                     }
                 } else if (hit.collider.gameObject.tag == "Bush") {
                     berryCollect = GameObject.Find (hit.collider.gameObject.name).GetComponent<BerryCollect> ();
                     berryCollect.currentBerry -= 1;
                     inventory.berries += 1;
                     PlayerPrefs.SetInt ("Berry", inventory.berries + saveBerries);
                     coolDown = maxCooldown;
                     if (berryCollect.currentBerry <= 0) {
                         GameObject.Find (hit.collider.gameObject.name).SetActive (false);
                     }
                 } else if (hit.collider.gameObject.tag == "Rock") {
                     rockSmash = GameObject.Find (hit.collider.gameObject.name).GetComponent<RockSmash> ();
                     rockSmash.currentRock -= 1;
                     inventory.rock += 1;
                     PlayerPrefs.SetInt ("Rock", inventory.rock + saveRock);
                     coolDown = maxCooldown;
                     if (rockSmash.currentRock <= 0) {
                         GameObject.Find (hit.collider.gameObject.name).SetActive (false);
                     }
                 }
             }
         }
     }// BECAUSE UNITY BUG
 }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        //FIXME
        //Case setup for equiping
        if (!equiped.activeSelf && Input.GetKeyDown(KeyCode.Alpha1))
        {
            isEquiped = true;
            equiped.SetActive(true);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            isEquiped = false;
            equiped.SetActive(false);
        }

        //Raycast
        Vector3    fwd = transform.TransformDirection(Vector3.forward);
        RaycastHit hit;


        if (Physics.Raycast(transform.position, fwd, out hit, 2))
        {
            //Debug.Log(hit.collider.tag);
            //FIXME
            //change to case for all interactable objects
            if (hit.collider.tag == "tree" && Input.GetMouseButtonDown(0) && isEquiped == true && isSwing == false)
            {
                equiped.GetComponent <Animation>().Play("swing");
                isSwing = true;
                StartCoroutine(swing());
                TreeChop treeScript = hit.collider.gameObject.GetComponent <TreeChop>();
                if (treeScript.treeHealth > 0)
                {
                    treeScript.treeHealth--;
                }
                else if (treeScript.treeHealth > 0 && treeScript.LogCount >= 0)
                {
                    treeScript.LogCount--;
                }
            }
        }


        //if (Input.GetKeyUp(KeyCode.I) && !InvPanel.gameObject.activeSelf)
        //{
        //    Debug.Log("I pressed and Inv not open");
        //    InvPanel.gameObject.SetActive(true);
        //    if(mouseLook.lockCursor)
        //    {
        //        unlockMouselook();
        //    }
        //}
        //else if(Input.GetKeyUp(KeyCode.I) && InvPanel.gameObject.activeSelf)
        //{
        //    //Debug.Log("I pressed and Inv was open");
        //    InvPanel.gameObject.SetActive(false);
        //    if(!CharPanel.gameObject.activeSelf)
        //    {
        //        lockMouselook();
        //    }
        //}

        //if (Input.GetKeyUp(KeyCode.C) && !CharPanel.gameObject.activeSelf)
        //{
        //    //Debug.Log("C pressed and Inv not open");
        //    CharPanel.gameObject.SetActive(true);
        //    if (mouseLook.lockCursor)
        //    {
        //        unlockMouselook();
        //    }
        //}
        //else if (Input.GetKeyUp(KeyCode.C) && CharPanel.gameObject.activeSelf)
        //{
        //    //Debug.Log("C pressed and Inv was open");
        //    CharPanel.gameObject.SetActive(false);
        //    if (!InvPanel.gameObject.activeSelf)
        //    {
        //        lockMouselook();
        //    }
        //}
    }