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 Conect11 · Sep 04, 2013 at 09:38 PM · combat

Trying to use a basic combat system

This really seems like it should make sense, and work, but clearly I'm missing something:

I'm trying to implement a basic combat system based on Jesse Etzler's tutorial on Youtube: link text However, I can't get it to work. In a nutshell I place a cube over the Player and make a label called "attack Area." Then I place the script from below on my enemy. The theory is that when the enemy enters the attack Area, the player pressing 1 will deal damage to them. Only, that's not happening. I truly do want to learn what I'm doing wrong here, and not just be a leech on people's knowledge. Have spent time reading up on tutorials, trying other scripts, searching on google, and I just don't get what I'm missing. The thing that stinks is the video tutorial makes this make perfect sense, but when I implement it, nothing works.

 var enemyHealth : int = 100;
    
 function Update () {
     if(this.enemyHealth <= 0) {
         playerHealth.curXp += 10;
         Destroy(this.gameObject);   
     }
 }

 function OnTriggerStay (col : Collider) {  
     if(col.gameObject.tag == "attackArea") {   
         if(Input.GetKeyDown("1")) {
             this.enemyHealth -=100;    
         }       
     }
 }

I can walk up to the enemy and swing away, with no effect. I have the attack script attached to them, the attack area tagged and attached to the player, and nothing. Any help, guidance, stinging criticism is greatly appreciated. God bless.

(Below, in case it needs to be referenced is the playerhealth script)

 var curHealth : int = 35;
 var maxHealth : int = 35;
  
 var healthtext : GUIText;
  
 static var curXp : int = 0;
 var maxXp : int = 100;
  
 var xptext : GUIText;
  
 var level : int = 1;
  
 function Start ()
 {
     healthRegen();
 }
  
 function Update ()
 {
     healthtext.text = curHealth + "hp / " + maxHealth;
     xptext.text = "Level " + level + " XP " + curXp + " / " + maxXp;
 
     if(curXp == maxXp)
     {
         levelUpSystem();
     } 
     if(curHealth <= 0 )
     {
         curHealth = 0;
         Application.LoadLevel(2);
     }
     if(curHealth > maxHealth)
     {
         curHealth = maxHealth;
     }
     if(Input.GetKeyDown("e"))
     {
        curHealth -= 10;
     }
     if(Input.GetKeyDown("r"))
     {
        curXp += 10;
     }
 }
  
 function healthRegen ()
 {
     for(i=1;i>0;i++)
     {
         yield WaitForSeconds(5.0);
  
         if(curHealth < maxHealth)
         {
             curHealth++;
         }
     }
 }
  
 function levelUpSystem ()
 {
     curXp = 0;
     maxXp = maxXp + 50;
  
     maxHealth += 15;
     level++; 
 }






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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Seizure · Sep 06, 2013 at 04:15 PM

Its hard to tell without seeing how your objects are setup, but I'd suggest putting a debug.log in you triggerEnter and see if it is activated. If not, make sure that on your cube you have its collider set to trigger (its a toggle button that is inactive by default)

Comment
Add comment · Show 1 · 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 Conect11 · Sep 06, 2013 at 04:33 PM 0
Share

silly me, uploading pictures now. Still learning how to do debugging. As far as trigger, yep, had that set.

avatar image
0

Answer by perchik · Sep 06, 2013 at 04:41 PM

Input flags are only called in the Update loop. Maybe you could set a flag to see if they pressed 1 in the update loop, but then check that flag on collision ?

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

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

18 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Trying to Highlight text with controller 1 Answer

Problem with combat. 1 Answer

Distance an object has travelled over a certain time? 1 Answer

movement and combat assistance 0 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