Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Brayden_H · May 20, 2013 at 04:58 AM ·

Tree Chopping Script Issues

Hey guys! I am having issues with the script attached to this question and i was wondering what those issues are. It's been bugging me for a bit now, It doesn't want to work so i'm willing to accept any feedback at the moment - I'm new to UnityJava so I'm having issues here and there!

This script is just meant to make the player cut down a tree, but it doesn't want to function correctly and it's pretty much halting progress for us right now.

 var Sphere : GameObject;
 var duration : float = 1;
 private var ShowGUI : boolean = false;
 private var Cutting : boolean = false;
 private var startTime : float = 0;
 
 
 
 function OnMouseOver (){
    var player = GameObject.Find("Player");
    if (Vector3.Distance(GameObject.Find("Player").transform.position, transform.position) > 2.0)
    return;
    ShowGUI = true;
    if (Input.GetMouseButtonDown(0)){
        Cutting = true;
        startTime = Time.time;
        
    }
    
        if (Cutting){  
        if (Time.time - startTime < duration){
            Instantiate(Sphere, transform.position, transform.rotation);
                    
     }
     else{
            Cutting = false;
            Destroy(gameObject);
            }
   }
 }
   
      function OnMouseExit(){
      ShowGUI = false;
      
     }
     
 
    function  OnGUI(){
     if (ShowGUI)
         GUI.Label(Rect (10, 10, 100, 20), "Cut this tree down!");
         
 } 

Any help is appreciated! Brayden

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kirbyrawr · May 20, 2013 at 06:28 AM 0
Share

Hello Brayden_H What's your problem? Don't be fear about being new to anything :) Also i wrote a script for cutting down trees with physics if you want i can post it but first tell me your error. Thanks.$$anonymous$$irbyRawr

avatar image Brayden_H · May 20, 2013 at 07:04 AM 0
Share

It doesn't actually come up with an error on any of the functions, etc. It just seems to not run on the left mouse click. I tested whether the $$anonymous$$ouseOver was working and it was, So i don't understand why it isn't running. If you need more information, just ask.

avatar image Kirbyrawr · May 20, 2013 at 08:12 AM 0
Share

Well, why you don't use raycast? it's better than find and you can do a manager. I will take a look at the code. And ins$$anonymous$$d of time, you can use a variable with the life of the tree, for example if the tree is more bigger you can put more life.

avatar image Brayden_H · May 20, 2013 at 08:16 AM 0
Share

I get what you mean, But do you $$anonymous$$d throwing up an example or linking me to a wiki page or something related to that. Sort of working on a progression of things with the current game and i'm sick, so my $$anonymous$$d is failing on me. Haha.

avatar image Brayden_H · May 20, 2013 at 09:48 AM 0
Share

I have one error at the moment.

"$$anonymous$$ Identifier: CutTree"

choque.collider.GetComponent(CutTree).Cutting();

Is that looking for the other game object, or..?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Kirbyrawr · May 20, 2013 at 08:21 AM

Well, my script is this:

CutTree.js

 #pragma strict
 var treelife = 100;
 var player : Transform;
 var treeragdoll : GameObject;
 var arbol : GameObject;
 var Player2 : GameObject;
 private var cut = false;
 private var cut2 = true;
 
 function Awake(){
 Cutting();
 }
 
 function Cutting(){ 
 
  treelife -=5;
  if(treelife <= 0){
    
    
    var treeragdollClone = Instantiate(treeragdoll, transform.position, transform.rotation);
 
     cut2 = false;
     // Kill ourselves
     Destroy(gameObject);
 
 
 }
   if(corte2 == false){
     print("Do Something here if you want")
 
     }
     }

RayCastManager.js

 //Private Variables.
 private var cut = false;
 //GameObject's Variables.
 var player : Transform;
 var player2 : GameObject;
 var playerdisable : GameObject;
 var choque : RaycastHit;
 
 
 
 
 function Update() {
 //Variables of the RaycastManager.
 var cam : Transform = Camera.main.transform;
 var rayo = new Ray(cam.position, cam.forward);
 
 
 
 
 
 
 //Tree Start Non Raycast!
 if(cut == false){
 print("Do Something here if you want")
 }
 //Tree End Non Raycast!
 
 //////////////////////
 
 if (Physics.Raycast(rayo, choque)) {
 
 //Cutting Trees Start
 if (choque.collider.tag == "Tree" && choque.distance <= 1.35){
 cut = true;
 }
 
 else{
 cut = false;
 }
 }
 //End Of the Raycast Manager.  
    
 //Another Functions!
  if (Input.GetMouseButtonDown(0)){
 if (cut == true){
   choque.collider.GetComponent(CutTree).Cutting();
 }
 }


Maybe it can have a little errors because i edit it a little. If you have any questions or errors tell me :) And if this question is right answered click on up button ^^

ATTACH THE RAYCAST MANAGER TO YOUR MAIN CAMERA and the OTHER SCRIPT TO A TREE. KirbyRawr.

alt text


shot_130512_025953.png (363.6 kB)
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brayden_H · May 20, 2013 at 10:19 AM -1
Share

Thanks heaps $$anonymous$$irbyRawr, Had to fix a couple of things but never-the-less it works!

avatar image Kirbyrawr · May 20, 2013 at 10:40 AM 0
Share

Oh that's good^^ happy to hear it!

avatar image Milan Kruger · Jul 13, 2014 at 05:58 AM 0
Share

Hey $$anonymous$$irbyRawr for the scripts you put up here did you use a normal tree from the terrain editor or did u make your own.

avatar image HarD-izzeR · Feb 03, 2016 at 04:56 PM 0
Share

CutTree.js(28,7): BCE0005: $$anonymous$$ identifier: 'corte2'.

HELP

avatar image
0

Answer by minecraft7089 · Sep 08, 2014 at 01:32 PM

It says "unknown identifier : corte2.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sheffieldlad · Sep 07, 2016 at 06:20 AM 0
Share

should be cut2 by the looks of things I haven't used this to try it but I'm pretty sure :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Accessing Script From Other Script Causes Lag? 1 Answer

Getting script from another script bug 1 Answer

Unity ignoring script modifications (and scenes mod) (uses old version source) 0 Answers

How to make a image flash infront of the camera 1 Answer

A problem with arrays 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges