- Home /
My distance variable is not changing?
So I am following Brackeys tutorial on YouTube as I just started with Unity on Friday. I have a script which sends out a raycast to find an object and reports the distance. It should show the distance but it does not do that for me.
It is a first person game survival game by the way.
Here is my script (Js) :
 #pragma strict
 
 var Damage : int = 50;
 var Distance : float;
 var MaxDistance : float = 1.5;
 var TheSystem : Transform;
 
 function Update ()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         //Attack animation
     animation.Play("AttackMace");
         
     }
 //    if (WeaponMace.animation.isPlaying == false)
 //    {
 //        WeaponMace.animation.CrossFade("Idle");
 //    }
 //    
 //    if (Input.GetKey (KeyCode.LeftShift))
 //    {
 //        WeaponMace.animation.CrossFade("Sprint");
 //    }
 //    
 //    if (Input.GetKeyUp(KeyCode.LeftShift))
 //    {
 //        WeaponMace.animation.CrossFade("Idle");
 //    }
 }
 
 function AttackDamage ()
     {
         //Attack function
         var hit : RaycastHit;
         if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
         {
             Distance = hit.distance;
             if (Distance < MaxDistance)
             {
                 hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
             }
         }
     }
I get no errors, I have assigned TheSystem variable to the camera too. I don't understand the problem.
Thanks.
Am stuck in that too if you got the answer please help
Hey have you got the answer for this ma stuck in it too I need help.
Answer by YoungDeveloper · Apr 27, 2014 at 08:46 PM
You aren't calling AttackDamage() function.
 if (Input.GetButtonDown("Fire1")){
     AttackDamage();
 }
Answer by XxNexusxX · Mar 22, 2017 at 07:18 AM
I had same prob. When I added in the event and linked the event to the AttackDamage function it solved it
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                