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 cakegamer · Dec 20, 2013 at 11:58 PM · randomnpc

random name selector

i want a random name selector for the npc where i can have a bunch of names in a list and it randomly picks a name from there and put it as that npc name and can reference that npc from a thread to use in dialogue and and i want it where it cant do this for more then one npc.

ps i have dislexsya sorry for that

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
5

Answer by HappyMoo · Jan 14, 2014 at 09:50 PM

 using UnityEngine;
 using System.Collections;
 
 public class RandomNameTest : MonoBehaviour {
 
     private string[] names = new string[] { "Peter", "Ron", "Satchmo" };
     public string GetRandomName()
     {
         return names[Random.Range(0, names.Length)];
     }
     
     void Start()
     {
         Debug.Log(GetRandomName() + " asks you nicely to use the learning modules");
     }
 }

http://unity3d.com/learn/tutorials/modules

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
1

Answer by AndyMartin458 · Dec 21, 2013 at 12:48 AM

The unity engine (and C#) have a random function that will grab a random number within a certain range. Here is a quick example for one character. TODO: Make a Names class to store all the names only once, and add a function which will return a name.

 void Start()
 {
 
 System.Random rand = new System.Random();
 
 int number = rand.Next(0, 500)
 
 List<string> names = new List<string>();
 for(int i = 0; i < 500; i++)
 {
     names.Add(A name that you grab somehow)
 }
 
 //now get a random name by using this
 string myName = names[number]; 
 
 }
Comment
Add comment · Show 6 · 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 AndyMartin458 · Jan 14, 2014 at 06:44 PM 0
Share

@cakegamer did you find this answer useful?

avatar image cakegamer · Jan 14, 2014 at 09:24 PM 0
Share

id not no how to use c# :( so i dont no how to make the name class :( sorry

avatar image sheffieldlad · Jan 14, 2014 at 09:26 PM 0
Share

$$anonymous$$aybe use an enum for the names?

avatar image cakegamer · Jan 14, 2014 at 10:06 PM 0
Share

@Andy$$anonymous$$artin458 sorry but i dont no how to make a name class im sorry my mentor wus teching me c# but wall im a newbe and i wus band frum the irc be cuse i have dislexsya

avatar image AndyMartin458 · Jan 15, 2014 at 01:51 AM 0
Share

@cakegamer aww man. I'm sorry about that. I'm sure that you can still learn it. I came across this article about the benefits of program$$anonymous$$g for those with dyslexia. http://io9.com/377561/why-dyslexics-are-good-computer-programmers

Show more comments
avatar image
0

Answer by CrazyKane · Jan 15, 2014 at 02:04 AM

You could use the random number generator, then make a switch statement.

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

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

Related Questions

Multiple Cars not working 1 Answer

Changing Objects Material Using My Array 1 Answer

How should I create a NPC System? 1 Answer

Help with spawning an object in a random location 1 Answer

Choose random background at start 1 Answer


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