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 Anonymous 1 · Dec 27, 2011 at 09:56 AM · touchguitextureguitextrpghittest

Gui , Message , Text, Touch and Question ?

PS- Sorry for the title of the question. So, i am trying to make a message box seen in rpgs and visual novels , i am working on Android platform and i have this script:

alt text

so what problem is , when i touch the gui on the screen , it skips the line "man,,." and everything that would come in between to the last one that is "i am getting late for the battle" So anyone got something i can do ? Thanx

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 Anonymous 1 · Dec 28, 2011 at 02:30 AM 0
Share

anyone ???

2 Replies

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

Answer by ks13 · Dec 28, 2011 at 08:17 AM

Why not use an array, then cycle trough your lines when the touchCont is touched?

Edit : ok, here's an exemple (just to let you know i code in C# usually so the code might not be right but the algorythm is) :

var touchCont : GUITexture; var line1 : GUIText; var line2 : GUIText; var line3 : GUIText; var lines = new Array; lines[0] = "man..."; lines[1] = "i am going to be late for the\nbattle"; var line : int = 0;

function FixdUpdate() { for (var touch : Touch in Input.touches) { if (touchCont.HitTest(touch.position)) line++; } AssignLine(); }

function AssignLine() { var linetab = lines[line].split("\n"); for (var i = 0; i < linetab.length; i++) { if (i == 0) line1 = linetab[i]; if (i == 1) line2 = linetab[i]; if (i == 2) line3 = linetab[i]; } }

Didn't write it properly, but the the idea is there :
Use an array to put all your sentences in, then cycle trough the array on each touch. Use another function to split the sentences into the lines as you see fit.

Edit : Below is the C# version of the code (JS and C# don't mix well in Unity so you better stick to only one of those) :

using UnityEngine; using System; using System.Collections; using System.Collections.Generic;

public class LineManager : MonoBehaviour //Symbolic name, change to whatever you want { //The texture to touch and change the lines public GUITexture touchCont; //The array containing the line to show private GUIText[] shownLines = new GUIText[3]; //The array containing the lines to cycle trough private string[] charLines = new string[] { "man...", "i am going to be late for the\nbattle", "some other line"}; //The current line number private int currentLine = 0;

 void FixedUpdate()
 {
     //Check for each touch if it's on the button(?), and launch the line showing if it is
     foreach (var item in Input.touches)
     {
         if (touchCont.HitTest(item.position))
             FillLine();
     }
 }

 void FillLine()
 {
     //Split the sentence in lines if there is more than 1 line
     var tmp = charLines[currentLine].Split(new char[] { '\n' });
     //A safety check
     if (tmp != null)
         //Go from first to last line and put in the array to show on screen
         for (int i = 0; i &lt; tmp.Length; i++)
         {
             shownLines[i].text = tmp[i];
         }
     //If the next line number is inferior to the max lines number we go to the next, othewise go to the begining
     if (currentLine == (charLines.Length - 1))
         currentLine++;
     else
         currentLine = 0;
 }

}

Comment
Add comment · Show 12 · 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 ks13 · Dec 28, 2011 at 08:40 AM 1
Share

Updated my answer

avatar image ks13 · Dec 28, 2011 at 09:37 AM 1
Share

it's the "backslash"n, need to change it to 'backslash'n, i think. (doesn't want to show the actual character)
As i said, i wrote it fast so there may be mistakes.

avatar image ks13 · Dec 28, 2011 at 09:54 AM 1
Share

Waid, did you just copy/paste the code i wrote?

avatar image ks13 · Dec 28, 2011 at 01:20 PM 1
Share

Once more, i did the code in haste and from what little i know of javascript, so you'll need to adapt it. From what i know, split is a member of string, so you have to use a string.
Edit : It doesn't recognize the type of the variable because i used var lines = new Array; without specifying the type of the variable.

avatar image ks13 · Dec 29, 2011 at 09:26 AM 1
Share

Hmm, the problem is i don't know how you manage the selection fo the GUIText. The code i wrote is for dynamically loading the sentences in an array. Since the array adresses don't change, the text should change when it's loaded in. So i suppose you should replace in your code line1, line2 and line3 by shownLines[0], shownLines[1] and shownLines[2].

Oh, and don't forget to validate the answer once it works (too many people leave to never come back forgetting to do this).

Show more comments
avatar image
0

Answer by Julien-Lynge · Dec 28, 2011 at 03:00 AM

You're overwriting the text later on. You have two for loops, both identical, and two if statements, both identical, so when one is true the other will be true. You assign to line1.text, and then assign again to line1.text immediately afterward. Did you mean to do the following?

line1.text = "man,,.";

line2.text = "i am going late for the"; line3.text = "battle";

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 Anonymous 1 · Dec 28, 2011 at 07:34 AM 0
Share

i think you got the most of it , what i want is on the first touch "man,,." should come on line1.text and on the seconds touch , line1.text will be "i am going late for " like in RPG they tell the story , so player read it then presses the button to see the next text

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GUITexture HitTest touch area 1 Answer

GUITexture Active and Enabled=false but still ı can click 1 Answer

Relative GUI positioning and Pixel Inset/Offset conversion 2 Answers

guiText before guiTexture 1 Answer

Dragging and Dropping GUITexture by TOUCH 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