x


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

more ▼

asked Jul 03 '12 at 07:14 PM

BakuJake13 gravatar image

BakuJake13
30 12 19 23

Basically you want to change the transform.position.y of the camera from the startingTarget till it reaches the endingTarget. Right?

Jul 03 '12 at 07:16 PM Luci85

right. and as its doing that it shows the gui text

Jul 03 '12 at 07:18 PM BakuJake13
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Jul 03 '12 at 09:16 PM

EdzUp[GD] gravatar image

EdzUp[GD]
53 1 3

its running okay. thanks

Jul 03 '12 at 09:51 PM BakuJake13
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jul 03 '12 at 07:50 PM

EdzUp[GD] gravatar image

EdzUp[GD]
53 1 3

could you put that in some code? thanks

Jul 03 '12 at 08:00 PM BakuJake13

I use js is that ok for your project?

Jul 03 '12 at 08:09 PM EdzUp[GD]

i would use c#, but js is ok too

Jul 03 '12 at 08:10 PM BakuJake13

Ok I will knock something together for ya, it wont be pretty but it will hopefully explain it enough for you to get a understanding from it :)

Jul 03 '12 at 08:41 PM EdzUp[GD]

okay. thanks

Jul 03 '12 at 08:57 PM BakuJake13
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jul 03 '12 at 09:03 PM

EdzUp[GD] gravatar image

EdzUp[GD]
53 1 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4151
x2994
x313
x43
x9

asked: Jul 03 '12 at 07:14 PM

Seen: 507 times

Last Updated: Jul 03 '12 at 09:51 PM