Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by DTJ Productions · May 13, 2010 at 12:30 AM · javascriptfps

Hurting and getting hurt

Hey I am making an FPS alien game. I have no clue how to get hurt when the "alien" hits me and how to make him die when I hit him. I have no script and would like one since I am a noob. Thanks

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
4

Answer by Peter G · May 13, 2010 at 12:59 AM

The tutorials do a good job explaining this. Here is the 3rd Person Platformer.

Basically here is the idea. The script below would go on the enemy

var damage : int = 5; var damageRadius = 1;

var player : Transform; //drag the player here in the inspector.

function Update () { if(Vector3.Distance(transform.position, player.position) <= 1) {

       //Alien Attacks
       player.BroadcastMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReciever);
  }

}

Create another script for the player with the following:

//This next function is a script on the player. var health = 10;

function ApplyDamage(damage : int) { health -= damage;

  if(health &lt;= 0) {
      Die();
  }

}

function Die () { //Respawn Player if wanted.

   Destroy(gameObject);

}

Comment
Add comment · Show 5 · 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 DTJ Productions · May 13, 2010 at 01:04 AM 0
Share

Some of the"//" kinda look like they should be in the script, should tweak this or take off some of the "//" or do nothing?

avatar image Peter G · May 13, 2010 at 01:41 AM 0
Share

Yes, they would be in a script, but I commented it out to signify that they would not be in this script. I'll edit my post to make more sense.

avatar image DTJ Productions · May 13, 2010 at 01:58 PM 0
Share

thank you very much for the scripts I will have to see if these work!

avatar image DTJ Productions · May 13, 2010 at 02:07 PM 0
Share

Okay so I just want to clarify this. THE FIRST SCRIPT GOES ON THE ALIEN WHILE THE SECOND IS ON THE DUD$$anonymous$$ I $$anonymous$$A$$anonymous$$E $$anonymous$$Y PLAYER IN THAT var Player:Transform. Now is their anything else I need to do or is it that when I add these scripts and I get close to the alien he hurts me? Also how do I have a HUD, or GUI to show my health.

avatar image Peter G · May 13, 2010 at 07:04 PM 0
Share

You are correct in which script goes on which and how to set it up.

A HUD is really a different question. I would search for it in the Answers, and the tutorial I gave you explains it. Basically create a GUI Script that finds the player, retrieves his health variable and displays an image accordingly.

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

Gun Firing help? 2 Answers

How to let my gun shoot ?? 0 Answers

How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers

Question about FPS and Raycasting Javascript 2 Answers

Unity FPS question 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