Narrative Scenes

Narrative.cs

calls Line class and print

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Narrative : MonoBehaviour {

	public string nextScene;

	private int lineId;
	private GameObject script;
	private Line line;
	private SceneTrans st;

	void Awake () {
		lineId = 0;
		line = GameObject.Find ("ScriptsManager/0").GetComponent<Line>();
		st = GameObject.Find ("trans").GetComponent<SceneTrans> ();
	}

	void Start(){
		line.Print ();
	}

	void OnMouseDown (){
		lineId = lineId + 1;
		script = GameObject.Find ("Narrative/ScriptsManager/" + lineId);
		if (script) {
			line = script.GetComponent<Line> ();
			line.Print ();
		} else {
			Debug.Log("line ID[" + lineId + "] does not exist.");
			Destroy (this.GetComponent<BoxCollider2D>() );
			st.Fade (nextScene);
		}
	}

	void Update () {
		if (Input.GetKeyDown (KeyCode.S)) {
			st.Fade (nextScene);
		}
	}
}

Line.cs

Contains each line with information of facial expressions and sound effects

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Line : MonoBehaviour {

	public enum Character
	{
		AMBER,
		JASPER,
		IOLITE,
		ROSALIND,
		JOSEPH,
		AWA
	};

	public enum FacialExpression
	{
		NEUTRAL,
		HAPPY,
		SURPRISED,
		SAD,
		ANGRY,
		HURT
	};

	public Character character;
	public FacialExpression facialExpression;
	[Multiline] public string line;
	public AudioClip soundEffect;

	public bool learningNewSpells;

	private GameObject[] chara;
	private Face face;
	private string charaName;
	private int charaId;
	private int faceId;
	private Text nt;
	private SoundEffect se;

	void Awake () {
		chara = new GameObject[] {
			GameObject.Find ("Amber/sprite"),
			GameObject.Find ("Jasper/sprite"),
			GameObject.Find ("Iolite/sprite"),
			GameObject.Find ("Rosalind/sprite"),
			GameObject.Find ("Joseph/sprite"),
			GameObject.Find ("AWA/sprite"),
		};

		nt = GameObject.Find ("NT").GetComponent<Text> ();
		se = GameObject.Find ("SE").GetComponent<SoundEffect> ();
	}

	public void Print() {

		charaName = character.ToString ();

		if (facialExpression == FacialExpression.NEUTRAL) {
			faceId = 0;
		} else if (facialExpression == FacialExpression.HAPPY) {
			faceId = 1;
		} else if (facialExpression == FacialExpression.SURPRISED) {
			faceId = 2;
		} else if (facialExpression == FacialExpression.SAD) {
			faceId = 3;
		} else if (facialExpression == FacialExpression.ANGRY) {
			faceId = 4;
		} else if (facialExpression == FacialExpression.HURT) {
			faceId = 5;
		}

		if (character == Character.AMBER) {
			charaId = 0;
		} else if (character == Character.JASPER) {
			charaId = 1;
		} else if (character == Character.IOLITE) {
			charaId = 2;
		} else if (character == Character.ROSALIND) {
			charaId = 3;
		} else if (character == Character.JOSEPH) {
			charaId = 4;
		} else if (character == Character.AWA) {
			charaId = 5;
		}

		face = chara[charaId].GetComponent<Face> ();
		face.FaceChange (faceId);
		se.Sound (soundEffect);
		nt.text = "<b>" + charaName + ":</b>\n" + line;

		if (learningNewSpells == true) {
			SpellLibrary.NewSpells ();
		}
	}

}

Face

controls characters’ facial expressions

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Face : MonoBehaviour {

	private SpriteRenderer face;

	public Sprite neutral;    //0
	public Sprite happy;      //1
	public Sprite surprised;  //2
	public Sprite sad;        //3
	public Sprite angry;      //4
	public Sprite hurt;       //5

	private Sprite[] faceId;

	void Awake () {
		face = this.GetComponent<SpriteRenderer> ();
		faceId = new Sprite[] { neutral, happy, surprised, sad, angry, hurt };
	}

	public void FaceChange (int id){
		face.sprite = faceId[id];
	}

	void Update () {

	}
}

StartScene

title screen and library initialisation

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StartScene : MonoBehaviour {
	private SceneTrans st;
	void Start () {
		st = GameObject.Find ("trans").GetComponent<SceneTrans> ();
		SpellLibrary.Empty ();
	}

	void OnMouseDown () {
		st.Fade ("Narrative01");
	}
}

Advertisements