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 Dwaring28720 · Oct 22, 2014 at 09:17 PM · c#guiscrollviewguilayouthealth

ScrollWindow AutoUpdating value help :(

Hi, really new to unity and c# here but learning quite a bit from tutorials, ive just got stuck on 1 little bit here and i cant seem to find a proper desription. ive made a scrollview window (included a picture of my results alt text

and its scrolling through the value instead of waiting for the value to change (basically ive got a health script which works fine when a mob does damage) but i was trying to make a small combat log style window but it doesnt seem to wait for a change in value, i've put a line in the wrong place so im hoping someone could just point me in the right direction.

thanks for any help on this (syntax is a killer for me, so difficult to pick up)

 using UnityEngine;
 using System.Collections;
 
 public class combat_log : MonoBehaviour {
     public Vector2 scrollPosition = Vector2.zero;
     public string longString = System.Convert.ToString(playerhp.curhp);
 
     void LateUpdate ()    
     {
         ammendlog(0);
     }
 
     void OnGUI() 
     {
         GUI.Box (new Rect (Screen.width - 798, Screen.height - 125, 352, 123), "");
         GUI.skin.label.alignment = TextAnchor.MiddleLeft;   
         GUILayout.BeginArea (new Rect (Screen.width - 798, Screen.height - 125, 352, 123));
         scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (350), GUILayout.Height (121));
         scrollPosition.y = Mathf.Infinity;
         GUILayout.Label (longString);
         GUILayout.EndScrollView ();
         GUILayout.EndArea ();
     }
 
 public void ammendlog(float adj) 
     {
     longString += "\n" + " Current Health : " + System.Convert.ToString (playerhp.curhp);
     }
 }
scrollable window.jpg (25.5 kB)
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

1 Reply

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

Answer by MarksTeq · Oct 22, 2014 at 10:47 PM

You're calling ammendLog(0) once per frame.

According to the Manual:

LateUpdate: LateUpdate is called once per frame, after Update has finished. Any calculations that are performed in Update will have completed when LateUpdate begins. A common use for LateUpdate would be a following third-person camera. If you make your character move and turn inside Update, you can perform all camera movement and rotation calculations in LateUpdate. This will ensure that the character has moved completely before the camera tracks its position.

You could try something like:

 int prevHP = playerhp.curhp; //Create a new var - Note: I was unsure of type
 
 void LateUpdate ()
 {
     if(playerhp.curhp != prevHP) //Keep checking if HP has changed
     {
         ammendlog(0); //if it has ammendlog()
         prevHP = playerhp.curhp;
     }
 }
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 Dwaring28720 · Oct 23, 2014 at 07:08 AM 0
Share

worked flawlessly thanks especially for the commenting on it too, thats what i always look for in an answer because i can see where i was going wrong, i can see now but just putting it without the If block in the update it was updating every frame regardless of any change.

thanks very much for your helpalt text

scrolling22.png (71.2 kB)

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

Invisible BeginScrollView thumb 0 Answers

Putting Dictionary/List using foreach as buttons in a scroll view? 3 Answers

Multiple Cars not working 1 Answer

Can you use GUIStyle with GUILayout? 0 Answers

Scrollbar is not appearing in my list, I am using Unity 4.6 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