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 PRninja8488 · Oct 27, 2014 at 01:58 AM · c#listrandomstring

(c#) display a random string at game over

Hey all, I'm trying to set up a game over script that will display a random string of text.

 public void GameOver()
     {
         string[] dead = new List
         {"gameover1", 
         "gameover2",
         "gameover3",
         "gameover4",
         "gameover5"}
         gameOverText.text = dead[Random.Range(0, dead.length)];
         gameOver = true;
     }

The issue is, when I go back to Unity, it tells me that there is a unexpected symbol "gameOverText". I must be missing a typo or a command or something, because it worked fine before I tried to add the random aspect. Being such a nooblet, I don't put it past myself to have missed something gigantic.

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 jpthek9 · Oct 27, 2014 at 02:17 AM

  public void GameOver()
      {
          string[] dead = new List
          {"gameover1", 
          "gameover2",
          "gameover3",
          "gameover4",
          "gameover5"}**;**
          gameOverText.text = dead[Random.Range(0, dead.length**-1**)];
          gameOver = true;
      }


Comment
Add comment · Show 4 · 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 PRninja8488 · Oct 27, 2014 at 02:24 AM 0
Share

I would like very much to say that this worked, and it looks like it will, but now it's decided that "List" and "length" are words from some ancient undecipherable language. Any thoughts on how I might fix that?

avatar image jpthek9 · Oct 30, 2014 at 12:19 AM 0
Share

OH YEAH! Sorry it's a little bit late but make sure you type 'Using System.Collections.Generic' without quotes.

avatar image PRninja8488 · Oct 30, 2014 at 04:01 AM 0
Share

Okay, I did that, and "length" is working, but "list" is still red.

avatar image jpthek9 · Oct 30, 2014 at 01:19 PM 0
Share
 public void GameOver()
       {
           string<string> dead = new List<string>;
          dead.Add("Gameover1"); dead.Add("Gameover2"; [and so on..]
           gameOverText.text = dead[Random.Range(0, dead.length**-1**)];
           gameOver = true;
       }

Okay last shot at it...

avatar image
0

Answer by Kiwasi · Oct 30, 2014 at 04:56 AM

You typically don't create arrays by declaring a list.

Try new string[] {...}

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Random role assigning from string array 1 Answer

How to Detect Touch on a Random String from a List? 1 Answer

Distribute terrain in zones 3 Answers

Value will not return from ArrayList, C# 1 Answer

Can't remove number from list,Random number from list and delete it from list 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