I have the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Printer : MonoBehaviour
{
// ´ò×Ö»ú²ÎÊý
private bool finished = false; // ÊÇ·ñ´òÓ¡Íê³É
//
public string Text; // ´ò×Ö»úÒªÏÔʾµÄÎı¾¼°Îı¾´úÂë
//
public int PrintDelay = 5; // ´òÓ¡ÑÓ³Ù
//
public Color CharColor = new Color(1, 1, 1, 1); // ÎÄ×ÖµÄÑÕÉ«
public int CharSize = 24; // ÎÄ×ֵijߴç
public Font Font; // ÎÄ×ÖµÄ×ÖÌå
public Font FontCn; // ÖÐÎÄÎÄ×ÖµÄ×ÖÌå
//
public AudioClip voice; // ´ò×Ö»úÒôЧ
//
public int CharSpace = -9; // ×Ö·û¼ä¾à£¨ÍƼöcharSize*3/8£©
public int CharSpaceCn = 0; // ÖÐÎÄ×Ö·û¼ä¾à
public int LineSpace = 8; // Ðмä¾à£¨ÍƼöcharSize/3*2£©
// ´ò×Ö»úÄÚ²¿±äÁ¿
private char[] silentChars = new char[] { // ²»²¥·ÅvoiceµÄ×Ö·û
' ',
'
',
‘,’,
‘.’,
‘:’,
‘£¬’,
‘¡£’,
‘£º’
};
//
private string printText; // ´ò×Ö»úÒªÏÔʾµÄÎı¾¼°Îı¾´úÂë
//
private AudioSource audioSource; // ÒôÔ´×é¼þ
//
public GameObject charPrefab; // ×Ö·ûʵÀýÔ¤ÖƼþ
private List chars = new List(); // ×Ö·ûʵÀýÁбí
//
private List charEffects = new List(); // ×Ö·ûЧ¹ûÁбí
//
private Vector3 charPos = new Vector3(0, 0, 0); // ÏÂÒ»¸ö×Ö·ûÏÔʾµÄλÖÃ
//
private int printed = 0; // ÒѼì²é×ÖÊý
//
private int delay = 0; // ÏÔʾÏÂÒ»¸ö×ÖÇ°µÄÑÓ³Ù
//
private bool afterBackslash = false; // ÊÇ·ñÔÚ·´Ð±¸Üºó
private bool readingCodeName = false; // ÊÇ·ñÕýÔÚ¶ÁÈ¡ÎÄ×Ö´úÂë
private bool readingCodeValue = false; // ÊÇ·ñÕýÔÚ¶ÁÈ¡ÎÄ×Ö´úÂëÖµ
//
private string codeName = “”; // ÎÄ×Ö´úÂëµÄÃû×Ö
private string codeValue = “”; // ÎÄ×Ö´úÂëµÄÖµ
void Start()
{
audioSource = GetComponent<AudioSource>();
printText = Text;
}
void Update()
{
if (printed == printText.Length) { finished = true; }
else
{
finished = false;
if (printed < printText.Length && delay > 0) { delay--; }
else
{
for (int i = printed; i < printText.Length; i++)
{
printed++;
char c = printText*;*
if (readingCodeName) // ¶ÁÈ¡Îı¾´úÂëÃû
{
if (c == ‘=’)
{
readingCodeName = false;
readingCodeValue = true;
}
else
{
codeName += c;
}
}
else if (readingCodeValue) // ¶ÁÈ¡Îı¾´úÂëÖµ
{
if (c == ‘]’)
{
readingCodeValue = false;
switch (codeName)
{
case “sleep”:
delay = int.Parse(codeValue);
return;
case “delay”:
PrintDelay = int.Parse(codeValue);
break;
case “color”:
CharColor = String.ToColor(codeValue);
break;
case “size”:
CharSize = int.Parse(codeValue);
break;
case “font”:
Font = Resources.Load(codeValue);
break;
case “fontCn”:
FontCn = Resources.Load(codeValue);
break;
case “voice”:
voice = Resources.Load(codeValue);
audioSource.clip = voice;
break;
case “charSpace”:
CharSpace = int.Parse(codeValue);
break;
case “charSpaceCn”:
CharSpaceCn = int.Parse(codeValue);
break;
case “lineSpace”:
LineSpace = int.Parse(codeValue);
break;
case “position”:
charPos = String.ToVector3(codeValue);
break;
case “tremble”:
trembleEffect effect = new trembleEffect();
effect.Read(codeValue);
charEffects.Add(effect);
break;
case “/tremble”:
int index = charEffects.FindIndex(i => i is trembleEffect);
charEffects.RemoveAt(index);
break;
default:
Debug.LogWarning(LogWarning.unknownTextCode);
break;
}
}
else
{
codeValue += c;
}
}
else if (afterBackslash) // ´òÓ¡ÏÂÒ»¸ö×Ö·û
{
Print(c);
afterBackslash = false;
return;
}
else // ¼ì²â×Ö·û
{
switch (c)
{
case ’
': // »»ÐÐ
charPos.x = 0;
charPos.y -= CharSize + LineSpace;
break;
case ‘/’: // Ç¿ÖÆ´òÓ¡ÏÂÒ»¸ö×Ö·û
afterBackslash = true;
break;
case ‘[’: // ¶ÁÈ¡Îı¾´úÂë
codeName = “”;
codeValue = “”;
readingCodeName = true;
break;
default: // ´òÓ¡
Print(c);
return;
}
}
}
}
}
}
private void Print(char c)
{
bool contains = false;
GameObject charInstance = Instantiate(charPrefab, this.transform);
Character charScript = charInstance.GetComponent();
Text charText = charInstance.GetComponent();
charText.text = c.ToString();
charText.color = CharColor;
charText.fontSize = CharSize;
charText.font = (c > 32 && c < 127) ? Font : FontCn;
charInstance.transform.position = charPos + this.transform.position;
charInstance.transform.Translate(320, -240, 0);
List effects = new List();
foreach (charEffect a in charEffects)
{
if (a is trembleEffect)
{
trembleEffect effect = new trembleEffect();
effect.args = a.args;
effects.Add(effect);
}
}
charScript.effects = effects;
charPos.x += (c > 32 && c < 127) ? (CharSize + CharSpace) : (CharSize + CharSpaceCn);
delay = PrintDelay;
foreach (char i in silentChars) { if (i == c) contains = true; }
if (!contains) audioSource.PlayOneShot(audioSource.clip);
}
public bool Finished()
{
return finished;
}
Idk how it works, or what it does, as i’m borrowing it from github, (link to repository here, btw GitHub - ItsEndel/UndertaleTemplate: made by unity ) i’ve never actually worked with this sort of code before, (i mean, what are these characters? it looks like nonsense!) and i’m completely hopeless when it comes to this. im getting the following errors:
Assets//UndertaleTemplate-main/Assets/Prefabs/Printer/Printer.cs(33,9): error CS1012: Too many characters in character literal
Assets//UndertaleTemplate-main/Assets/Prefabs/Printer/Printer.cs(34,9): error CS1012: Too many characters in character literal
Assets//UndertaleTemplate-main/Assets/Prefabs/Printer/Printer.cs(35,9): error CS1012: Too many characters in character literal
I proceeded to look it up, and was met with the answer “make the quotes double quotes” i did, but then it said “cannot implicitly convert char to string”. I’m stupid and don’t know what this means. Please help!