Jump to content
Unity Insider Forum

Abspann/Story - Scrollender Text Problem


Tiles

Recommended Posts

Ich versuche gerade einem Text das Scrollen beizubringen. So richtig verstehe ich noch nicht was welche Variable genau tut. Aber es tut was es soll. Es scrollt, ist einigermassen mittig, und wird nur noch im Scrollview rectangle angezeigt.

 

Ein Problem habe ich aber. Der Text scrollt bis oben hin bevor er verschwindet. Das würde ich aber gern 50 Pixel eher verschwinden lassen. Ich müsste also das ganze Scrollview Rectangle um 50 Pixel nach unten versetzen. Ich weiss aber nicht wo oder wie ich das ändern soll. In der Scripting Referenz gibts da leider mal wieder keinen grossen Hinweis zu :/

 

#pragma strict
var y : float = 600.0; // scrollingposition bottom. That`s where the text starts to scroll upwards.Tweak the starting position in the editor.
var scrollPosition : Vector2;
function Start () {
}
function Update () {
y = y -1;  //scrollingspeed. Text gets moved upwards by one
}
function OnGUI () {
   scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (800), GUILayout.Height (600)); // Scrollview Rectangle. The area where the text gets displayed.
GUI.Label(Rect((Screen.width/2-100)-40,y,200,50),"Directed By");
GUI.Label(Rect((Screen.width/2-100)-40,y+20,200,500),"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
   GUILayout.EndScrollView ();
}

Link zu diesem Kommentar
Auf anderen Seiten teilen

Für mich bleibt Unity`s GUI Lösung trotzdem ein Kruscht. Da hat man schon nen Drag n Drop Editor für den gesamten 3D Content, und dann muss man sich bei einem der wichtigsten Sachen, der UI, immer noch durch Code hangeln und die irrsten Kopfstände anstellen nur um mal einen simplen String irgendwo auf Position zu bringen. Cool geht anders, seufz ...

 

Aber genug gerantet. Ich schau jetzt lieber mal dass ich das hier zum funktionieren bekomme :)

Link zu diesem Kommentar
Auf anderen Seiten teilen

Sodele. Scrollt wie es soll. Und ist über den Editor einstellbar ...

 

#pragma strict

var y : float = 500.0; // scrollingposition bottom. See function start
var scrollPosition : Vector2;  //The vector 2 that handles the scroll position
var scrollspeed:float=0.5;  //The scrollspeed.

// -------------------- View Rectangle

var viewrectYtop: float=50.0; //This is where the text vanishes at the top
var viewrectYbottom: float=200.0;// This is where the text appears at the bottom

//-------------------Text position and width

var textwidth:float=300; // This is to position block of text.
var titlewidth:float=50; // This is to position title text

// ---------------------------------------------------------------------------------------------------------------------------------------------

function Start () {

   y=Screen.height-viewrectYbottom;  // This sets the scrolling text position at the botton of the view rectangle

}

function Update () {
   y = y - scrollspeed;  //scrollingspeed. Text gets moved up by this speed
}

function OnGUI () {

   scrollPosition = GUI.BeginScrollView (Rect (50,viewrectYtop,Screen.width-100,Screen.height-viewrectYbottom),scrollPosition, Rect (0, 0, 220, 200));

   GUI.Label(Rect((Screen.width/2-titlewidth)-40,y,titlewidth,50),"Directed By"); //Title text
   GUI.Label(Rect((Screen.width/2-textwidth/2)-40,y+20,textwidth,400),"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed ... ");// Block Text.

   //Line Breaks gets calculated automatically. To add a new paragraph you need ot add another GUI Label line.

   GUI.EndScrollView ();
}

 

Nu muss ich nur noch mal guggn wie man dem ganzen einen GUI Style beibügelt. Ich glaub los gings indem man einen anlegt oder so :D

 

Soooo kompliziert gelöst, sniff -.-

Link zu diesem Kommentar
Auf anderen Seiten teilen

Archiviert

Dieses Thema ist jetzt archiviert und für weitere Antworten gesperrt.

×
×
  • Neu erstellen...