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 adrennalinpro · May 15, 2013 at 04:51 AM · randomdeathmessagediehealth

How to make death messages show at random?

I have a deathScript and need to know how to create different messages show at random once dead. Right now they go to console which is fine for now. What I need is a bit of script that will cause different messages to appear. My current code just does one but as I've said there needs to be more messages and done random. my current script for sending the message is:

 if(health <= 0)
 {
 Print("DEATHMESSAGEHERE")
 Destroy(Player);
 }

I need up to ten different messages, and display a random one each time you die. My theory is that you could make the damage of the enemy a random number between 1-10. Then I would make the health = 11 by default and if the equality is 1-10 then show a message for that designated number. The only problem is, I cannot figure out how to implement the math into the JavaScript (which is indeed what I am using). I would show the formula I am using for it but it's on another computer. I believe it is something to the effect of:

 Math.random()

and I would have a long stream of code to tell it what to randomize and what the actual perimeters are.

EVEN IF YOUR SOLUTION IS TOTALLY UNRELATED TO MY THEORY PLEASE POST TO CORRECT/INFORM ME. I need to know so that I can 1. have random death messages and 2. have random death animations and 3. have random awesomeness.

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 robertbu · May 15, 2013 at 05:00 AM 0
Share

For a random message, look into array's and Random.Range().

 var my$$anonymous$$essages : String[];  // Initialize in the inspector

Then to get the message:

 if (my$$anonymous$$essages.Length > 0)
   Debug.Log(my$$anonymous$$essage(Random.Range(0,my$$anonymous$$essages.Length));


1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ikriz · May 15, 2013 at 06:37 AM

Create a Death Class with animation, message and awesomness.

  public class Death {
         string message;
         AnimationClip animation;
         int dramalevel;
     
         public void Die()
         {
          // do stuff when player dies
         }
     }

Then for each type of death add it to a list

 List<Death> deaths = new List<Death>();
 Death tmp = new Death();
 tmp.message = "OMG i died..";
 tmp.animation = myanimation;
 tmp.dramalevel = 1000;
 deaths.Add(tmp);

and then when death occurs:

 int selectedDeath = Random.Range(0,deaths.Count-1);
 deaths[selectedDeath].Die();

and there you have it.

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 adrennalinpro · Apr 14, 2014 at 05:32 AM 0
Share

Dude you're a genius....

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

14 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

Related Questions

Player Health Damage 2 Answers

Scene not restarting after player death 2 Answers

Player taking damage on collision. Can't get the script to work!? 1 Answer

Creating a Asteroid health script 5 Answers

Player Character Health 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