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 question was closed Mar 28, 2014 at 07:07 AM by getyour411 for the following reason:

Duplicate Question

avatar image
0
Question by Wintergrasped · Mar 28, 2014 at 06:46 AM · attackmelee

Melee Attack System

I have been learning to work with unity for a while now both C# and JavaScript but on my recent project the one thing I havent yet figured out is an attack system for my current project. All I need to get moving agin is an ttack system shown below also please dont just post a sctipt and be like "Here This Works" try to explain why it works how it works and what makes it work.

alt text

Health Script

var curHealth : int = 100; var maxHealth : int = 100;

 var healthtext : GUIText;
  
  
  
 function Start () {
  
  
 healthRegen();
  
 }
  
  
  
  
  
 function Update () {
  
  
 healthtext.text = curHealth + " / " + maxHealth;
  
  
 if(curHealth < 0 ) {
  
 curHealth = 0;
  
  
 }
  
  
 if(curHealth > 100) {
  
  
 curHealth = 100;
  
  
 }
  
  
  
 if(Input.GetKeyDown("e")) {
  
 curHealth += 10;
 ManaScript.curmana -= 20; 
 }
  
  
  
 }
  
  
  
  
 function healthRegen () {
  
  
 for(i=1;i>0;i++) {
  
  
  
 yield WaitForSeconds(1.5);
  
 if(curHealth < maxHealth) {
  
 curHealth++;
  
 }
  
  
 }
  
  
 }

Mana Script

 #pragma strict
     
 
     static var curmana : int = 100;
     var maxmana : int = 150;
      
     var manatext : GUIText;
      
      
     InvokeRepeating("manaRegen", 2, 5.0);
       
     function Start () {
      
     
      
     }
      
      
      
      
      
     function Update () {
      
      
     manatext.text = curmana + " / " + maxmana;
      
      
     if(curmana < 0 ) {
      
     curmana = 0;
      
      
     }
     
      
      
     if(curmana > 100) {
      
      
     curmana = 100;
      
      
     }
      
      
      
     if(Input.GetKeyDown("1")) {
      
     curmana -= 10;
      
     }
      
      
      
     }
      
      
      
      
     function manaRegen () {
      
     curmana += 5;
      
      
      
     }
desc.gif (9.0 kB)
Comment
Add comment · Show 1
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 getyour411 · Mar 28, 2014 at 07:07 AM 0
Share

Questions like this have been asked a thousand times.

1 Reply

  • Sort: 
avatar image
0

Answer by getyour411 · Mar 28, 2014 at 07:06 AM

For the first, use an OverlapSphere and sort through the colliders comparing distance and direction. For the second, use an OverlapShere fairly vanilla.

Many examples are out there showing the exact syntax, variations, other alts, tuts, vids, YouTube vids, etc.

https://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

20 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 avatar image

Related Questions

Multiple Cars not working 1 Answer

MOB HP - Subtract on Hit if Near 1 Answer

Error CS8025: Parsing error. HELP! 1 Answer

Wont Change Color 0 Answers

Add force to GameObject 2 Answers


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