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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by hynra · Jan 04, 2014 at 06:42 PM · meleemelee attack

Player Attack malfunction

I Have scripts that player send message dammage to enemies using raycast hit. but every player hit the enemies the functions didnt work. here the scripts

* MeleeScript.js (player script assigned on weapon object with mecanim, sending dammage message to enemies)

 var TheDammage : int = 50;

 var Distance : float;

 var MaxDistance : float = 1.5;

 var TheSystem : Transform;

 var theAnimator : Animator;
 
 function Update ()
 {

     if(Input.GetButtonDown("Fire1")) 
     {
         theAnimator.SetBool("Hit01", true);    
     }
     if(Input.GetButtonUp("Fire1")) 
     {
         theAnimator.SetBool("Hit01", false);    
     }
     
     if(Input.GetButtonDown("Fire2")) 
     {
         theAnimator.SetBool("Hit02", true);    
     }
     if(Input.GetButtonUp("Fire2")) 
     {
         theAnimator.SetBool("Hit02", false);    
     }
 }
 
 function AttackDammage ()
 {

         //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("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
             }
         }
 }

* EnemyHealth.js (default health of enemies, its reciever dammage from player)

 var Health = 100;
 
 function ApplyDammage (TheDammage : int)
 {

     Health -= TheDammage;
     
     if(Health <= 0)
     {
         Dead();
     }
 }


 function Dead()
 {

     Destroy (gameObject);
 }

Even the distance between player and enemy very close, its still no happens

alt text

How to resolve the problem ? Thanks before.

11.jpg (102.5 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ShadyD · Jan 04, 2014 at 10:16 PM

Hello,

Following the Brackeys Tutorial I see :), awesome tutorial serie imo.

Anyway, you're sending the message to the transform. Try changing

   hit.transform.SendMessage(..

to

  hit.gameObject.SendMessage(..
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 hynra · Jan 05, 2014 at 07:20 AM 0
Share

i have changed the code just like you suggest, but i got error. here the message from console

 Assets/Script/$$anonymous$$eleeSystem.js(57,37): BCE0019: 'gameObject' is not a member of 'UnityEngine.RaycastHit'. 
avatar image ShadyD · Jan 05, 2014 at 09:31 AM 0
Share

Oh wait, this is really silly. Didn't see it before. Your code was correct. Change it back to hit.transform.Send$$anonymous$$essage(.. Problem is, you just never call your AttackDammage() function.

Changing

 if(Input.GetButtonDown("Fire1")) 
     {
        theAnimator.SetBool("Hit01", true);   
     }

to

 if(Input.GetButtonDown("Fire1")) 
     {
        theAnimator.SetBool("Hit01", true);  
        AttackDammage();

     }

should do the trick.

avatar image hynra · Jan 05, 2014 at 04:29 PM 0
Share

Oh yea, my bad. Its work, very helped. Thanks mate. But its make me confused, if you follow the tutorial from brackeys, he explained dat script, and also the function of attackdamage not call in update function, but the script absolutelly worked. What the different ?

avatar image ShadyD · Jan 05, 2014 at 06:58 PM 0
Share

Good to hear it works now :)! I never got that far with the brackey tutorials, I just followed a few (about 10 or so I think) to get started with Unity.

$$anonymous$$aybe download his project and compare your code. It could be that he accidently had a second (or finished) script working on the player. Link me to the video, I can take a look if you'd like.

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

Code don't function when 0 Answers

How can I attach a colldier that moves with the enemies sword in an attack animation? 0 Answers

How could I combine melee weapons and rays? 1 Answer

Weapon attack 0 Answers

noob question about melee combat 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