Hi there I am creating a game for a school project and I’m having real troubles. With my code I was having problems with converting some values to another so i removed the script as i wanted to test other features. However all the errors on screen seem to be compiler errors not allowing me to enter play mode. I realised that all my scripts including the one i removed said that there were compiler errors and it could not be loaded. There are no errors in any of the scripts especially one that only has 10 lines of code. I was wondering what the solution to this problem is as it is getting frustrating not being able to run my program.
Thanks in advance
What errors show on the console.?
1 Like
If Unity is claiming there are compiler errors you either have compiler errors or you just have one of those freak situations where restarting Unity/deleting the library/deleting the solutions file, stuff like that might fix it.
Best thing to do, is sure your errors here and share one of the scripts it’s telling you has a compiler error.
1 Like
Brathnann:
If Unity is claiming there are compiler errors you either have compiler errors or you just have one of those freak situations where restarting Unity/deleting the library/deleting the solutions file, stuff like that might fix it.
Best thing to do, is sure your errors here and share one of the scripts it’s telling you has a compiler error.
I made new scripts and copied over the code and that seems to have done the trick now I just have one genuine error I don’t know how to fix
We can’t help you fix it if you don’t post what it is.
1 Like
Yanne065:
Use code tag .
where and what does that mean what do i have to replace
No copy the script here by using code tag as screen shot is really hard to see
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextWriter : MonoBehaviour
{
private static TextWriter instance;
private List<TextWriterSingle> textWriterSingleList;
private void Awake()
{
instance = this;
textWriterSingleList = new List<TextWriterSingle>();
}
public static TextWriterSingle AddWriter_Static(Text uiText, string textToWrite, float timePerCharacter, bool invisibleCharacters, bool removeWriterBeforeAdd, Action onComplete)
{
if (removeWriterBeforeAdd)
{
instance.RemoveWriter(uiText);
}
return instance.AddWriter(uiText, textToWrite, timePerCharacter, invisibleCharacters, onComplete);
}
private TextWriterSingle AddWriter(Text uiText, string textToWrite, float timePerCharacter, bool invisibleCharacters, Action onComplete)
{
TextWriterSingle textWriterSingle = new TextWriterSingle(uiText, textToWrite, timePerCharacter, invisibleCharacters, onComplete);
textWriterSingleList.Add(textWriterSingle);
return textWriterSingle;
}
public static void RemoveWriter_Static(Text uiText)
{
instance.RemoveWriter(uiText);
}
private void RemoveWriter(TextWriter uiText)
{
for (int i = 0; i < textWriterSingleList.Count; i++)
{
if (textWriterSingleList[i].GetUIText() == uiText)
{
textWriterSingleList.RemoveAt(i);
i--;
}
}
}
private void Update()
{
for (int i = 0; i < textWriterSingleList.Count; i++)
{
bool destroyInstance = textWriterSingleList[i].Update();
if (destroyInstance)
{
textWriterSingleList.RemoveAt(i);
i--;
}
}
}
/*
* Represents a single Textwriter instance
* */
public class TextWriterSingle
{
private Text uiText;
private string textToWrite;
private int characterIndex;
private float timePerCharacter;
private float timer;
private bool invisibleCharacters;
private Action onComplete;
public TextWriterSingle(Text uiText, string textToWrite, float timePerCharacter, bool invisibleCharacters, Action onComplete)
{
this.uiText = uiText;
this.textToWrite = textToWrite;
this.timePerCharacter = timePerCharacter;
this.invisibleCharacters = invisibleCharacters;
this.onComplete = onComplete;
characterIndex = 0;
}
// Returns true on complete
public bool Update()
{
timer -= Time.deltaTime;
while (timer <= 0f)
{
//Display next character
timer += timePerCharacter;
characterIndex++;
string text = textToWrite.Substring(0, characterIndex);
if (invisibleCharacters)
{
text += "<color=#00000000>" + textToWrite.Substring(characterIndex) + "</color>";
}
uiText.text = text;
if (characterIndex >= textToWrite.Length)
{
//Entire string displayed
if (onComplete != null) onComplete();
return true;
}
}
return false;
}
public TextWriter GetUIText()
{
return uiText;
}
public bool IsActive()
{
return characterIndex < textToWrite.Length;
}
public void WriteAllAndDestroy()
{
uiText.text = textToWrite;
characterIndex = textToWrite.Length;
if (onComplete != null) onComplete();
TextWriter.RemoveWriter_Static(uiText);
}
}
}
Brathnann:
Where?
nevermind it says its waiting moderator approval first
Brathnann:
Where?
also whilst im waiting how do i make a gameobject a prefab? i thought you could just drag it into assets but unity wont let me
That’s what you do. Please explain what you mean exactly by “unity wont let me”.