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
0
Question by Haugkall · Jan 27, 2018 at 07:52 PM · buttonsdialogue

Recreating adventure game dialouge system (newb)

I'm trying to recreate this old adventure game dialouge as a newb challenge, I started learning C# and unity two days ago.

alt text

I have already created a menu from which I can access a new scene where the conversation is to take place. I created four buttons and lined them up as in the old game. I created an empty on which I want to place the script and from which I want the buttons to recieve information dialouge. I have done something similar once and I'm trying to achieve a similar result again without a tutorial, except this is probably a bit more cluttery than simply changing a number in a text UI element from one variable to another.

Anyway here is what I have started with in the empty's script. A variable for each button and when you click on any of the buttons the variable number is going to change to 2 and if variable is equal to two do this to the buttons or the portrait's dialouge. But I'm getting errors already "Cannot implicitly convert type int' to bool'" on line 24.

I'm a bit lost and wonder if someone could give me some advice. :)

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class DialougeScript : MonoBehaviour {
 
     int one;
     int two;
     int three;
     int four;
 
     public Text text;
     // Use this for initialization
     void Start () {
         one = 1;
         two = 1;
         three = 1;
         four = 1;
     
     }
     
     public void Dialouge () {
     
     if (one = 1){
         text.text = "Hello who are you?";
     if (two = 1){
         text.text = "I'm lost, where are we?";
     if (three = 1){
         text.text = "I wish I had something to eat.";
     if (four = 1){
         text.text = "I've got to go I think.";
         
         }
                 }
             }
         }
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

I'm probably going to need one function for each button right, so I can call different functions for when different buttons are being pressed?

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
1
Best Answer

Answer by Airman · Jan 27, 2018 at 08:06 PM

Hi there,

It seems that on your lines that contain an if statement, you're using the standard ='s sign, which is for assignment: (E.g. int A = 4 would set a variable A equal to 4.) You'll want to use the =='s sign which is for boolean expressions (E.g. if(A == 4) { text.text = "Hello world"; }.

 if (one = 1){ //needs to be changed to one == 1
          text.text = "Hello who are you?";
      if (two = 1){ //needs to be changed to two == 1
          text.text = "I'm lost, where are we?";
      if (three = 1){ //needs to be changed to three == 1
          text.text = "I wish I had something to eat.";
      if (four = 1){ //needs to be changed to four == 1
          text.text = "I've got to go I think.";
          
          }
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 haroldgeronimo · Jan 27, 2018 at 08:38 PM

use double equal sign "==" on conditions one equal sign signifies variable assignment while two equal sign i used for equality conditions

ex: var i = 0; // assignment of data to variables if(i==0){ ... } // equality condition

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 haroldgeronimo · Jan 27, 2018 at 08:38 PM 0
Share

Oh sorry late answer

avatar image
0

Answer by Haugkall · Jan 27, 2018 at 08:14 PM

Thanks that fixed it. :)

Comment
Add comment · Show 3 · 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 Airman · Jan 27, 2018 at 08:26 PM 0
Share

No problem; good luck with it.

avatar image Haugkall Airman · Jan 27, 2018 at 08:34 PM 0
Share

Hmm yeah thanks if you don't $$anonymous$$d me asking I'm trying to change the text in the button. Am I correct in thinking the name of the text object has to be made into a variable and then changed with text.text = text1.ToString("Hello who are you?"); It's not working right now using UnityEngine; using UnityEngine.UI; using System.Collections;

 public class DialougeScript : $$anonymous$$onoBehaviour {
 
     int one;
     int two;
     int three;
     int four;
     int text1;
     int text2;
     int text3;
     int text4;
     
     public Text text;
     // Use this for initialization
     void Start () {
         one = 1;
         two = 1;
         three = 1;
         four = 1;
         Dialouge();
     
     }
     
     public void Dialouge () {
     
     print ("test");
     
     if (one == 1){
             text.text = text1.ToString("Hello who are you?");
     if (two == 1){
         text.text = "I'm lost, where are we?";
     if (three == 1){
         text.text = "I wish I had something to eat.";
     if (four == 1){
         text.text = "I've got to go I think.";
         
         }
                 }
             }
         }
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 
avatar image Airman Haugkall · Apr 09, 2018 at 09:52 AM 0
Share

Hi there,

$$anonymous$$y apologies as I haven't checked the unity answer forums in a while. If you're wanting a system where you press a button and then dialogue appears, you'll need to create a button widget and provide it the functionality to do just that. I have a unity project uploaded onto my github that does this: https://github.com/RLangridge/AnswerProject.

The basic idea is that you have a script that has a set of buttons and you add a listener to the onclick list of the appropriate button. The listener would have the functionality to change the text of the speaker based on the button that you pressed.

I did this with the following code:

 /// <summary>
     /// We use this function to assign an onclick function to each button. As the functionality of the buttons
     /// does not differ except from which index we should be using when referencing dialogue, it's better
     /// to just throw in a lambda here so that we don't have to re-write a heap of code.
     /// </summary>
     /// <param name="_index"></param>
     private void SetupOnClickFunctionsForButtons(int _index)
     {
 //We retrieve a button from our public button array, DialogueButtons
         var btn = DialogueButtons[_index];
 //We then add a listener to it, which is just a function that I've defined below.
         btn.onClick.AddListener(() => OnButtonClick(_index));
     }
 
 //This function is fired off when the player clicks a button with this function as the listener (I.e the buttons that had this added as a listener above).
     private void OnButtonClick(int _index)
     {
 //Speech text is the Text widget that I've defined for the computer and DialogueResponses is an array of strings.
         SpeechText.text = DialogueResponses[_index];
     }

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

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

Related Questions

Conversation Bubbles and starting it 1 Answer

Dialouge isnt working 1 Answer

I'm trying to make a button change two images at once? 1 Answer

Change mouse button click in existing code to ui button click.,Change the existing code from mouse click to ui buttons. 1 Answer

Any way to pass the function of a listener as a string? 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