So im trying to make a story line for the unity game which is already complete. everything was going swimmingly but this script. here it is:
<code>using System.Collections.Generic;
using System.Threading.Tasks;
public class storyLineController : MonoBehaviour
public FPSController fpc;
private readonly string folderpath = @$"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}too-bad-to-be-true";
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
public List<string> messages = new List<string>();
public TextMeshProUGUI messagesPlaceholder;
public TextMeshProUGUI newMessageAlert;
public int newMessageCount;
// Start is called before the first frame update
new Task(Program).Start();
using (FileStream fs = new FileStream(@$"{folderpath}ESSgr.txt", FileMode.Create, FileAccess.Write))
messages.Add($"[{sw.Elapsed.Minutes}:{sw.Elapsed.Seconds}] program booted up n");
foreach ( var message in messages )
bytes = Encoding.ASCII.GetBytes($"{message}n");
UnityEngine.Debug.Log(Encoding.ASCII.GetString(bytes));
sendMessage("james: Hey bro, james here. get in the car i left you, its right next to you.");
while (!vs.isInVechile) { };
sendMessage("james: if you are in a car already, come by me. i have something to chat about");
public void sendMessage(string message)
newMessageAlert.text = $"+{newMessageCount} new message(s)";
using (FileStream fs = new FileStream(@$"{folderpath}ESSgr.txt", FileMode.Open, FileAccess.Write))
foreach (var message1 in messages)
bytes = Encoding.ASCII.GetBytes($"[{sw.Elapsed.Minutes}:{sw.Elapsed.Seconds}] {message1}n");
UnityEngine.Debug.Log(Encoding.ASCII.GetString(bytes));
messagesPlaceholder.text = $"{messages[messages.Count]} n {messages[messages.Count - 1]}";
UnityEngine.Debug.Log($"messagePlaceholder text is: {messagesPlaceholder.text}");
<code>using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using System.Text;
using System.Threading.Tasks;
using TMPro;
public class storyLineController : MonoBehaviour
{
public FPSController fpc;
public vechileSwitch vs;
private readonly string folderpath = @$"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}too-bad-to-be-true";
byte[] bytes = null;
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
public List<string> messages = new List<string>();
public TextMeshProUGUI messagesPlaceholder;
public TextMeshProUGUI newMessageAlert;
public int newMessageCount;
// Start is called before the first frame update
void Start()
{
new Task(Program).Start();
sw.Start();
using (FileStream fs = new FileStream(@$"{folderpath}ESSgr.txt", FileMode.Create, FileAccess.Write))
{
messages.Add($"[{sw.Elapsed.Minutes}:{sw.Elapsed.Seconds}] program booted up n");
foreach ( var message in messages )
{
bytes = Encoding.ASCII.GetBytes($"{message}n");
fs.Write(bytes);
}
UnityEngine.Debug.Log(Encoding.ASCII.GetString(bytes));
}
}
void Program()
{
newMessageCount++;
sendMessage("james: Hey bro, james here. get in the car i left you, its right next to you.");
while (!vs.isInVechile) { };
newMessageCount++;
sendMessage("james: if you are in a car already, come by me. i have something to chat about");
}
public void sendMessage(string message)
{
newMessageAlert.text = $"+{newMessageCount} new message(s)";
messages.Add(message);
using (FileStream fs = new FileStream(@$"{folderpath}ESSgr.txt", FileMode.Open, FileAccess.Write))
{
foreach (var message1 in messages)
{
bytes = Encoding.ASCII.GetBytes($"[{sw.Elapsed.Minutes}:{sw.Elapsed.Seconds}] {message1}n");
fs.Write(bytes);
}
UnityEngine.Debug.Log(Encoding.ASCII.GetString(bytes));
}
messagesPlaceholder.text = $"{messages[messages.Count]} n {messages[messages.Count - 1]}";
UnityEngine.Debug.Log($"messagePlaceholder text is: {messagesPlaceholder.text}");
}
}
</code>
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using System.Text;
using System.Threading.Tasks;
using TMPro;
public class storyLineController : MonoBehaviour
{
public FPSController fpc;
public vechileSwitch vs;
private readonly string folderpath = @$"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}too-bad-to-be-true";
byte[] bytes = null;
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
public List<string> messages = new List<string>();
public TextMeshProUGUI messagesPlaceholder;
public TextMeshProUGUI newMessageAlert;
public int newMessageCount;
// Start is called before the first frame update
void Start()
{
new Task(Program).Start();
sw.Start();
using (FileStream fs = new FileStream(@$"{folderpath}ESSgr.txt", FileMode.Create, FileAccess.Write))
{
messages.Add($"[{sw.Elapsed.Minutes}:{sw.Elapsed.Seconds}] program booted up n");
foreach ( var message in messages )
{
bytes = Encoding.ASCII.GetBytes($"{message}n");
fs.Write(bytes);
}
UnityEngine.Debug.Log(Encoding.ASCII.GetString(bytes));
}
}
void Program()
{
newMessageCount++;
sendMessage("james: Hey bro, james here. get in the car i left you, its right next to you.");
while (!vs.isInVechile) { };
newMessageCount++;
sendMessage("james: if you are in a car already, come by me. i have something to chat about");
}
public void sendMessage(string message)
{
newMessageAlert.text = $"+{newMessageCount} new message(s)";
messages.Add(message);
using (FileStream fs = new FileStream(@$"{folderpath}ESSgr.txt", FileMode.Open, FileAccess.Write))
{
foreach (var message1 in messages)
{
bytes = Encoding.ASCII.GetBytes($"[{sw.Elapsed.Minutes}:{sw.Elapsed.Seconds}] {message1}n");
fs.Write(bytes);
}
UnityEngine.Debug.Log(Encoding.ASCII.GetString(bytes));
}
messagesPlaceholder.text = $"{messages[messages.Count]} n {messages[messages.Count - 1]}";
UnityEngine.Debug.Log($"messagePlaceholder text is: {messagesPlaceholder.text}");
}
}
as you can see, im not using unity’s default start and update methodes. that would cause too much lag because i would have had to write if code in update and that would cause a ton of lag. instead, i tried so call program methode asynchronously.
thing is, the first code line in the sendMessage methode, newMessageAlert.text = $"+{newMessageCount} new message(s)";
, works, but others dont. besides, im not getting any logs.
i would be so happy if someone found the solution.
p.s. is there a better way to make the script wait other than while loop?