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 rochenray · Oct 20, 2014 at 04:29 AM · with

Why is this chat box sending messages from bottom to top?

Hello! I need help. I have this chatbox found in the Photon Demo but its sending messages from bottom to top.... which.... no chat box in history ever really does... any way i can make it send from top to bottom instead??

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(PhotonView))]
 public class InRoomChat : Photon.MonoBehaviour 
 {
     public Rect GuiRect = new Rect(0,0, 323,170);
     public bool IsVisible = true;
     public bool AlignBottom = false;
     public List<string> messages = new List<string>();
     private string inputLine = "";
     private Vector2 scrollPos = Vector2.zero;
 
     public static readonly string ChatRPC = "Chat";
 
     public void Start()
     {
         if (this.AlignBottom)
         {
             this.GuiRect.y = Screen.height - this.GuiRect.height;
         }
     }
 
     public void OnGUI()
     {
         if (!this.IsVisible || PhotonNetwork.connectionStateDetailed != PeerState.Joined)
         {
             return;
         }
         
         if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
         {
             if (!string.IsNullOrEmpty(this.inputLine))
             {
                 this.photonView.RPC("Chat", PhotonTargets.All, this.inputLine);
                 this.inputLine = "";
                 GUI.FocusControl("");
                 return; // printing the now modified list would result in an error. to avoid this, we just skip this single frame
             }
             else
             {
                 GUI.FocusControl("ChatInput");
             }
         }
 
         GUI.SetNextControlName("");
         GUILayout.BeginArea(this.GuiRect);
 
         scrollPos = GUILayout.BeginScrollView(scrollPos);
         GUILayout.FlexibleSpace();
         for (int i = messages.Count - 1; i >= 0; i--)
         {
             GUILayout.Label(messages[i]);
         }
         GUILayout.EndScrollView();
 
         GUILayout.BeginHorizontal();
         GUI.SetNextControlName("ChatInput");
         inputLine = GUILayout.TextField(inputLine);
         GUILayout.EndHorizontal();
         GUILayout.EndArea();
     }
 
     [RPC]
     public void Chat(string newLine, PhotonMessageInfo mi)
     {
         string senderName = "anonymous";
 
         if (mi != null && mi.sender != null)
         {
             if (!string.IsNullOrEmpty(mi.sender.name))
             {
                 senderName = mi.sender.name;
             }
             else
             {
                 senderName = "Player " + mi.sender.ID;
             }
         }
 
         this.messages.Add(senderName +": " + newLine);
     }
 
     public void AddLine(string newLine)
     {
         this.messages.Add(newLine);
     }
 }
Comment
Add comment · Show 2
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 Wisearn · Oct 20, 2014 at 07:28 AM 0
Share

$$anonymous$$ight be as easy as changing this line:

  for (int i = messages.Count - 1; i >= 0; i--)
  {
      GUILayout.Label(messages[i]);
  }

to this:

  for (int i = 0; i < messages.Count; i++)
  {
      GUILayout.Label(messages[i]);
  }
avatar image rochenray · Oct 22, 2014 at 02:50 AM 0
Share

AND.... yes! it was that easy! thank you so much!!

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Create objects with script? 2 Answers

How can I tell if my character controller is in contact with a wall? 1 Answer

Multiple people working in the same project 4 Answers

WWW Video with control buttons 0 Answers

Help with Ragdoll 2 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