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 oscarkool · Jan 18, 2014 at 04:23 AM · attackmeleerpg-game

Melee Attack C# Script Help

Been working on this script for the after noon and I just can't seem to get it to work so I'm reaching out to the community. I've basically set up a trigger on my characters weapon with an invisible collider that will (hopefully) register an attack. At the moment, nothing happens when I click the mouse button, no animation, nothing. Unity gives me a yellow error 'Unreachable Code Detected' for the 'yield return new WaitForSeconds(swingRate);' so there's an error there. This code is part of my main controller code, I'm not gonna past 200+ lines of code but feel free to ask for more code if it's needed. Again, no red errors so I know I'm close... Any assistance you can give me will be awesomeeeeee!

 // Melee Attacking Script
     IEnumerator MeleeSwing()
     {
         while(true)
         {
             if(Input.GetMouseButtonDown(0))
             {
                 anim.SetBool("Attack", true);
                 meleeTrigger.SetActive(true);
                 
                 yield return new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).length);
 
                 meleeTrigger.SetActive(false);
                 
                 break;
                 
                 yield return new WaitForSeconds(swingRate);
             }
             else
             {
                 yield return 0;
             }
         }
     }
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 Scutah · Jan 18, 2014 at 04:48 AM

The Unreachable Code Detected is because you have a break before a yield. break will break the the while loop, which also means your function wont return anything. I very rarely use yield so I cannot comment on it.

Comment
Add comment · Show 6 · 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 oscarkool · Jan 18, 2014 at 04:53 AM 0
Share

Okay, what can I use ins$$anonymous$$d for my situation? Basically I want to have a delay after I attack so the player cant keep attacking over and over. I want the animation to finish before allowing another attack, like a 1.5 second delay. I'm new to mecanim as well.

avatar image Scutah · Jan 18, 2014 at 05:06 AM 0
Share

I'm not new to program$$anonymous$$g but I am new to mecanim so i'll do some looking for you

avatar image oscarkool · Jan 18, 2014 at 09:13 AM 0
Share

Been trying the last 4 hours to fix it and still no dice... why is program$$anonymous$$g such a bitch?

avatar image getyour411 · Jan 18, 2014 at 09:25 AM 0
Share

Here's an example of a delay. In Start(),

 attackTimer = 1.5;

In Update(),

 if (attackTimer > 0)
 attackTimer -= Time.deltaTime;
         
 if (attackTimer < 0)
 attackTimer = 0;

Ignore input/attack button if attackTimer != 0 Not the most efficient but something to get you going.

avatar image oscarkool · Jan 19, 2014 at 01:46 AM 0
Share

Ok great I'll try to get something working with that. $$anonymous$$an, who would have guessed that a good melee attacking script would be one of the hardest things to code lol

Show more comments

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

Enemy will only take (melee) damage when the distance is below 1 (ie. A zero with decimals after it) 2 Answers

Not identifying the collider? 2 Answers

please help with my melee attack animation 1 Answer

Bayonet Action Transform 0 Answers

Melee attacking, using force and health values 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