Question by 
               _Sewa · Jan 18, 2016 at 04:19 PM · 
                c#scripting problemnot workingtree  
              
 
              Tree chopping
I´ve made a script to cut trees when the player is closer than 10 units! Why the code isnt working? I get no errors!!
using UnityEngine; using System.Collections;
public class TreeHealth : MonoBehaviour { public int Health; public Transform player;
 void Start () 
 {    
     
 }
 
 void Update () 
 {
     if(Health < 0) 
     {
         if(Vector3.Distance(player.transform.position, player.position) < 10f)
         {
             if(Input.GetKeyDown(KeyCode.Mouse0))
             {
                 Ray ray = new Ray (player.transform.position, player.transform.forward);
                 RaycastHit hit;
                 
                 if(Physics.Raycast(ray,out hit, 10f))
                 {
                     if(hit.collider.gameObject == gameObject)
                     {
                         --Health;
                     }
                 }
             }
         }
     }
     
     if (Health <= 0)
     {
         Destroy(gameObject);
     }
 }
}
               Comment
              
 
               
              put Debug logs into your code and see at which point it goes no further
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                