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 jakieb · Nov 25, 2013 at 11:21 PM · methods

Using a method output in an if statement.

I am trying to get a grasp on some basics an using methods and so I came up with a scenario with some flavor text and I want to see if I am going about this in the right way.

I am trying to make it so that when input a,s,t happens different text will pop up (for now in the debug log).

Also if anyone has a better suggestion on how to do this, by all means please let me know.

Thank you, and this is my first question so if you need more info please let me know.


using UnityEngine; using System.Collections;

public class StoryProgression : MonoBehaviour {

 public string deathText;
 public string escapeText;
 public string goodEscapeText;


 int choiceNumber;


 string[] firstChapter = {"Welcome, you must escape from the prison. Hurry! You have to get out before nightfall!",
     "You see that your in a jail, no one is around. What do you do?",
     "You made it out of your cell, however you did not notice the guard sleeping in the corner earlier. He seems to be in a deep sleep. What do you do?",
     "You are almost out of the gate at eh top of the stairs, you can see the sunlight, dusk is approaching. You hear a yell for help from a young child behind you. What do you do?"};

 void Start () 
 {


     deathText = "You made a bad decision, and you died.";
     escapeText = "Disreguarding the child and thinking only of yourself, you made it out of that horrid" +
         "dungeon! You travel for a week going from village to village. One day you wander into a village" +
         "and find you like the look of this happy place and decide to settle down. You marry a good looking woman " +
             "and raise a happy family on the farm. Yay!";
     goodEscapeText = "Taking the hand of the child, you burst out of the prison!...to be continued.";
     Debug.Log(firstChapter[0]);

 
 }

 void Update () 
 {

     if(Input.GetKeyDown(KeyCode.Return))
     {
         Debug.Log(firstChapter[1]);


         ///How would I implement my method to make the following work?
         if (choiceNumber = 1)
         {
             Debug.Log("You beat the snot out of the bars, nothing else happens, expect your knuckles are now bleeding");
         }

         if (choiceNumber = 2)
         {
             Debug.Log("You see that you are in a extreamly clean cell.");
         }

         if (choiceNumber = 3)
         {
             Debug.Log("You see a loose fist sized stone in the wall, you wiggle it out. ");
         }
     }

 }

 int StoryMove()
 {
     if(Input.GetKeyDown(KeyCode.A))
     {
         choiceNumber = 1;
         Debug.Log("You Attack!");
         return choiceNumber;
     }

     if(Input.GetKeyDown(KeyCode.S))
     {
         choiceNumber = 2;
         Debug.Log("You use your observational skills to look anything conspicuous");
         return choiceNumber;
     }

     if(Input.GetKeyDown(KeyCode.T))
     {
         choiceNumber = 3;
         Debug.Log("You try and talk to someone");
         return choiceNumber;
     }
 }

}

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 PhilRousse · Nov 25, 2013 at 11:30 PM 0
Share

Hard to understand what should be result. Can write a user story please?

1 Reply

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

Answer by gerleim · Nov 26, 2013 at 12:12 AM

I guess from the text included in the code ("You Attack!" - "You beat the snot out of the bars...) that after the user selects "A", something happens in reaction.

You need a game state for that. For now it can be a public variable. For starters, something like:

 public GameState MyGameState;
 
 public class GameState
 {
    public string Action;
    /* other fields may come here like in which room is your player */
 }
 

Setting the GameState Action:

 if(Input.GetKeyDown(KeyCode.A))
 {
    MyGameState.Action = "A";
 }
 

Evaluating user choice:

 if(MyGameState.Action = "A"))
 {
    /* do action */
 }
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 jakieb · Nov 26, 2013 at 12:31 AM 0
Share

That makes a lot of sense. I guess it's time to figure out states for good. Thanks!

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

17 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

Related Questions

Moving and Attacking 0 Answers

Can't Override Virtual Method In Inherited Class 1 Answer

Change calling object with extension method 1 Answer

Does Unity support extension methods? 3 Answers

Calling Method within a Method from a different Class 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