Credits Camera Script

hey guys. i have a credits level with gui text, a camera and two empty game objects. i want the camera to move down and show the gui text while moving down on its y axis. i also made this c# script:

using UnityEngine;

using System.Collections;

public class CreditsCamera : MonoBehaviour {
public Transform startingTarget;
public Transform endingTarget;
public float cameraSpeed;

// Use this for initialization
void Start () {
if(startingTarget == null)
Debug.LogWarning(“There is no starting target for the camera”);

if(endingTarget == null)
Debug.LogWarning(“There is no ending target for the camera”);

}

// Update is called once per frame
void Update () {

}
}

do u think you can help me? c# would be good

Ok so what your doing is basically moving the camera down and displaying the relevant text as required as the camera passes by? If thats what your trying to do what I would do is place all your strings in a array and then update the GUIText as required.

You could do it by

  1. moving the camera with transform.translate to move the camera slowly down

When it moves down a line then do:
2)increment a counter so the game knows you have moved down a line
3)change all the GUIText with the new data from the array
4)move the camera back up then start again (1)

keep doing that until you have displayed the entire credits and when thats done reset the line counter so it runs through again OR go back to main menu.

The main bonus with doing this is you wont need hundreds of GUIText entries and its easy to change the array than rehashing all the GUIText entries then it is to have hundreds of entries it will also keep the ram requirements of your game down.

Here ya go its not elegant and there are probably hundreds of ways to do it but this way you wouldnt have to have hundreds of GUIText’s to scroll through.


#pragma strict
var ScreenGUI:GUIText[];		//assign GUIText arranged in scene to ScreenGUI
var CreditText:String[];
var Cam:Camera;					//assign scene camera in inspector
var CurrentLine:int =0;			//Current line of CreditText array
var TextMoved:float = 0.0;		//how far the text has moved for resetting
var ScrollSpeed:float = 0.0025;	//Scroll speed of the text

function Start () {
	//setup the CreditText array to whatever length you need with extra lines so it scrolls
	//onto the screen and off the screen before being reset
	CreditText = new String[ 40 ];
	
	//Initialise the array
	for ( var CTPos:int =0; CTPos<40; CTPos++ ) {
		CreditText[ CTPos ] = "";
	}
	
	//set the credits text here this will set the array so when its displayed there is 
	//something to display
	CreditText[ 10 ] = "A test";
	CreditText[ 11 ] = "To see if it works";
	CreditText[ 13 ] = "Here is a simple credits";
	CreditText[ 14 ] = "text scroller!";
	
	setGUIText( 0 );			//set the first lines of text
}

function Update () {
	//update the positions of the GUIText on the screen
	for ( var SGP:int = 0; SGP<=ScreenGUI.Length -1; SGP++ ) {
		ScreenGUI[ SGP ].transform.Translate( Vector3( 0, ScrollSpeed, 0 ) );
	}
	//adjust the check variable
	TextMoved += ScrollSpeed;
	
	if ( TextMoved >0.1 ) {
		TextMoved =	0.0;		//reset the TextMoved variable
		CurrentLine++;			//Increment the line
		setGUIText( CurrentLine );
		//move it all back again
		for ( SGP = 0; SGP<=ScreenGUI.Length -1; SGP++ ) {
			ScreenGUI[ SGP ].transform.Translate( Vector3( 0, -0.1, 0 ) );
		}
		if ( CurrentLine>CreditText.Length ) CurrentLine =0;
	}
}

function setGUIText( line:int ) {
		//This function will setup the GUI text
		var CLine:int = line;
		
		//the line+ScreenGUI.length means we can change the length of the array and it wont
		//break the code.
		for( var TAP:int = 0; TAP

I have uploaded a package of the scene and script to here as some of the code doesnt seem to appear properly this is a unity package so should be just import into anywhere and it should run in the editor fine.