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 Martin 3 · Oct 31, 2010 at 05:21 PM · aienemymelee

Standart Enemy Melee

I have a model of a monster (enemy), and It have a "attack" animation. I have programmed the enemy to run towards the player when close, but how to make these steps:?

  1. Play animation "attack" when player is very close
  2. Minus Players HP by one

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JesusChristChangedMe · Oct 31, 2010 at 10:25 PM

you have the hard part done. so when the monster hits you then you should have your player deduct a life. todo that your going to have to use static variables. make a new script called health control and use a switch statement and whatever number of hits you allow your character to take from the monster all the way down to case:0. and you should have in the script where it says to play your animation and you player getting hit healthcontrol.HEALTH -= 1; so that takes away a life from your character and tells the health control script to exacute the first case.

so your health control would look something like this.

static var HEALTH = 3;
function Update()
{
switch(HEALTH)
{
case 3:
//whatever you want to happen before your hit goes here
break;
case 2:
//whatever you want to happen after your hit once goes here
break;

and so forth like that.

there is a really good torandotwins tutorial about health control. here is a link

http://www.unityprefabs.com/tutorials/wormgame/making-a-videogame-adding-lives-GUI-and-HUD-unity3d-engine.html

Comment
Add comment · Show 2 · 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 Jesus_Freak · Nov 01, 2010 at 12:53 AM 0
Share

you could also look for the youtube tutorials made by canned mushrooms.

avatar image Martin 3 · Nov 01, 2010 at 07:40 AM 0
Share

Uhm, Thats not really what I had in $$anonymous$$d. I need help with playing animation when the monster collides? with the player, and then a script to the player, that detects when enemy is colliding while playing the "attack" animation.

avatar image
1

Answer by JesusChristChangedMe · Nov 02, 2010 at 01:53 AM

persona kinda had it right but this is what i would use. ok now i know what you want.

make sure this is attached to your monster. you want when the monster hits you to play the attack animation. Just make sure you tag the player "player"

function OnCollisionEnter(hit:Collider) { if(hit.gameObject.tag == "player") { animation.Play("attack");//or whatever your animation name is //here goes what you want to do to your player's health

} }

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

Answer by Persona · Nov 02, 2010 at 01:39 AM

Umhn....I'll give it a try. This is a rough idea on how to do it since I'm not on Unity right now and some coding will be off but basically:

function OnCollisionEnter(){ if(other.gameObject.CompareTag("Player")){

Attack(); } }

function Attack(){ play animation; other.sendMessage("Hurt")

}

Basically if you hit something that's tagged player, it runs the attack sequence. That plays the animation and sends a message to the player called Hurt, which should be a function like Attack, that reduced the health by one(Health--). The animation is merely a formality, the damage is done regardless of connectivity.

This is a rough idea of how to do it. The coding isn't completely accurate as I'm going off the top of my head.

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

No one has followed this question yet.

Related Questions

Player Damage to enemy damage melee system 0 Answers

Complete AI Tutorial? 1 Answer

2D Random AI 1 Answer

free roaming enemy ai 1 Answer

Need help with knockback in C# Please! 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