- Home /
How do I change which camera is active based on text dialogue?
Hello,
I haven't found anything similar to this on the forum, so I apologize if I am re-posting an already solved issue.
Basically what I am trying to do is create a mini cut-scene. What I want to happen is to activate different cameras depending which character is currently "talking." I have my text currently going into an array, split based on the '\n' parameter in my Notepad file, and I can scroll through the text by pressing "Enter." What I'm wondering is if I can somehow use this array to solve the problem. Can I somehow add a marker to the text that will allow Unity to recognize that, for example, "if there is an # next to the line, it's speaker 1, and a $ is speaker 2." Then I could use those 2 "tags" of sorts to say "if text is of # group, activate camera 1" "if text is of $ group, activate camera 2." I hope that I'm explaining myself correctly...
Thanks, Drew
Answer by Zetya96 · Dec 08, 2017 at 07:26 PM
Well, if theres only 2 camera,you can just add a special character at the end of the string, and if the string ends with that char,then you switch camera.
If theres more camera,you can split your string into 2 part with like a splitter.
For example Hello stranger|1
Then when you read the line, you split it, and the first part is your text, the second is the id of the camera,you want to set active.
Answer by Psyk16 · Dec 08, 2017 at 07:29 PM
This is exactly what I need! However, I'm not entirely sure how I would do this in the scripts/text itself. Could you give me an example code/text for say, the following text:
Person 1: Hey how are you? Person 2: Good, you? Person 1: Fine thank you.
What/where would I put these markers, and how do I then access them in the script?
Thanks for the quick reply!!!
I currently am just using 1 camera, and moving it's location to a predeter$$anonymous$$ed Transform. Sorry, I forgot I changed my plan a little bit ago. But, if it's easier I can create another camera.
If you have the positions in an array, then its cleaner, then having multiple cameras (I think).
EDIT: sorry, I guess you have transforms in the array, because I assume you change the rotation of the camera, too?
Your answer
Follow this Question
Related Questions
How to make UI elements same size regardless of distance 1 Answer
world canvases z fighting or rendering in the order when camera moves around 0 Answers
How to display text with the GUI Text object when using the Ultimate FPS Camera Asset 0 Answers
Accessing next Camera from array 1 Answer
Reference other scrips in prefab 1 Answer