Ok, so this is very simple. When I use this script in update, as usual, nothing wrong with it. Buuutt… its when the Replace(“”,“”) comes into update… it gets very weird. if you look at my script that converts words into another word:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class test : MonoBehaviour {
public bool canChangeName = true;
public bool checkforWord = false;
public GameObject InputFields;
public InputField User_Name;
public Text text;
public void Update()
{
if (canChangeName)
{
text.text = User_Name.text;
checkforWord = true;
if (checkforWord)
{
text.text = User_Name.text.Replace("Lost Syndicate", "INVALID");
text.text = User_Name.text.Replace("Lost_Syndicate", "INVALID");
text.text = User_Name.text.Replace("Lost_Sndicate", "INVALID");
}
if (Input.GetKeyDown(KeyCode.Return))
{
text.text = User_Name.text;
text.text = User_Name.text.Replace("Lost Syndicate", "INVALID");
User_Name.enabled = false;
InputFields.SetActive(false);
canChangeName = false;
}
}
}
}
you can test it out and everything but what its supposed to do is go through those “words” and replace them with “INVALID”. Now the problem starts here. When i tested it out… only the last word said “INVALID” (in this case it was “Lost_Sndicate”) now i dont know how to fix this, i tried removing it from checkforword and putted it below text.text but ONLY the bottom text gets converted. Here is my example
text.text = User.text;
// here is where the problem starts.
text.text = User.text.Replace("alpha1","INVALID") // doesnt work!
text.text = User.text.Replace("alpha2","INVALID") // doesnt work!
text.text = User.text.Replace("alpha3","INVALID") // doesnt work!
text.text = User.text.Replace("alpha4","INVALID") // works!
// Them scrambled around:
text.text = User.text.Replace("alpha3","INVALID") // doesnt work!
text.text = User.text.Replace("alpha4","INVALID") // doesnt work!
text.text = User.text.Replace("alpha2","INVALID") // doesnt work!
text.text = User.text.Replace("alpha1","INVALID") // works!
it only checks the last one, and doesnt check the others besides that last one.
does anybody understand why this is happening?