Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm posting this so that the code is available to whomever finds it helpful.
Slightly reduced code based on Noctis's suggestion.
StringBuilder DescriptionText = new StringBuilder();
async void RunDescription(StringBuilder description)
{
DescriptionText = description;
await Task.Delay(1000); // Short delay before the text starts printing so the window has time to load
new Thread(AddTextToTextBlock).Start();
}
void TextBlockDispatcher(string text)
{
TextBlock1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => TextBlock1.Inlines.Add(text)));
}
void AddTextToTextBlock()
{
foreach (char c in DescriptionText.ToString())
{
Thread.Sleep(30);
TextBlockDispatcher(c.ToString());
}
}
Sounds like the usual hoops you need to jump through. The only thing i might consider changing is instead of calling the dispatcher, and then checking if it has access, simply calling it directly on your object.
It should look kinda like :
TextBlock1.Dispatcher.BeginInvoke((Action)(() => /* logic here */ )
Saves you an call, but same same really.
You'll need to massage it in, since this is from the top of my head, but it should point you in the right direction.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
I am making a game in Unity, 2D and for the creation of levels, I have added a for loop so that a number of blocks is generated a certain number of times. The problem is that it never ends, that is, instead of ending on the game screen when the two blocks are created, it continues to generate blocks infinitely.
public void GenerateInitialBlocks()
{
for (int i = 0; i < 2; i++)
{
AddLevelBlock();
}
}
I have reset the Script in Unity because it usually gives compilation errors or crashes, but it still doesn't work. Thanks for read.
I believe the problem could be in how many times the method is called.
find where in the code the method is called (perhaps using search)
make sure it's called only once per level and not repeatedly when refreshing or repainting (scene updating methods).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to make a character move a certain distance then change direction when they travel a certain distance... the logic here in my code might be wrong I still have to work on that that's not the issue, the problem is my if statement doesn't execute
public class EnemyControl : MonoBehaviour
{
private int xMoveDirection=-1;
private float x;
void Start()
{
x=gameObject.transform.position.x;
}
void Update()
{
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(xMoveDirection,0);
if(x==0.00){
Debug.Log("helloimhere");
xMoveDirection=0;
x=x+1;
}
Any direct comparisons against floating point values will most likely fail, you're better off defining a range of values that are "close enough", for example Math.Abs(x) < 0.0001.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a random text, which can include special (for sendkeys) symbols like ), ( etc (obvious book, for example). Screening unsuitable too, becouse string send through the internet, so the size of string important. Can you suggest some decision?
Try this and see if your problems go away:
public void TypeCustomMessage(string message)
{
SendKeys.SendWait(Regex.Replace(message, #"(\+|\^|%|~|\(|\)|\[|]|\{|})", "{$1}"));
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm a beginner in C# and I make a quiz. My problem it is that when a question is asked that should make a loop so that the second question can be asked. I had the idea to use goto or return to turn over to the beginning but I have several events of clicks.
Here is an example:
private void Event1
{
//do something..
}
private void Event2
{
//do other things
}
private void Event3
{
//Here I want to return to the event 1 to make a loop
}
Is that possible?
If no are there other solutions?
I assumed that you want to bulid 3 question in series, enable the next options when current question is answered correctly.
If I'm right, first of all you should enable the first button only.
When first event raised and the answer was right , disable first button, then enable next one,so on until all questions were finished.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am making a game where people listen to determine whether something is black or white. I want to store how many times they got it correct and how many times they got it wrong in a database so they can see the old results.
What kind of database (like Sqlite) should I use? How should I save this information and display it later?
You can use BinarySerializtion, XMLSerialization,......
so first create a class:
[Serializable]
public class Result
{
Public int TimesRight {get;set;}
Public int TimesWrong {get;set;}
}
now in your game:
Result result = new Result();
result.TimesRight = x; //value of times right
result.TimesWrong = y; //value of times wrong
Now choose the way you want to save it, here are some references for Binary and XML serialization:
Binary Serialization
XML Serialization