#Yes but sorting is different in runtime
1 messages · Page 1 of 1 (latest)
I don't think it's obscured by other objects. When I hit play, I can move it if i select it in the hierarchy, but it is invisible. Sorry english isn't my first language
if (Mathf.Floor(Player.position.x) == point) // if the random point and player pos are at the same place
Replace that if-statement's expression with Input.GetKeyDown(KeyCode.X)
The "...Random.Range(Player.position.x + distmax..." causes your point to always be further away than your maxdistance. Be aware of that!
IEnumerator apparition()
{
while(true){
point = Mathf.Floor(Random.Range(Player.position.x + distmax, Player.position.x + (distmax*2))); // random point between the player and max distance
yield return new WaitForSeconds(10);// change point every 10 sec
}
}```
what will it do
well that's not rlly a problem it is ? i just want to randomize the apparition of my panel
You can test the conceptual solution, without any possible interference or derp from the expression logic
lets say your maxdistance has a value of 100, then the only values where your screen CAN appear are 100-200. so you run towards 100, but only reach 90 on the 10 seconds your yield gives you, now the IEnumerator runs again and the new values where your screen CAN appear are 190-290.
So unless your maxdistance is really low you might never reach your point variable.
Mathf.Floor() will round the number down to the nearest integer, which means point must always be an integer. It would be better to use something akin to Mathf.Approximately() or a custom one which allows you to adjust tolerance. (unless an integer is fine)
Set Apparition time to 30-60 while testing (for the update stuff)
It would also be better to write the if with >= instead of ==. Just to prevent you overshooting for some reason.
Most people will tell you: Don't == floats. Use Mathf.Approximately()
Because floats are not real numbers, they are scientific notations that have a lot of issues to look out for when diving deeper.
Even if you mathematically calculate two positions to become the same, the result might be different.
The most obvious limitation of floats is that they have a finite set of digits that they use to express both whole numbers and fractions.
1.000000
10.00000
100.0000
1000.000
10000.00
higher value leads to lower precision
if you made anything depend on Time.time instead of Time.deltaTime
it would start skipping frames after about 3 hours (if I recall correctly; not really important).
So, I tried that, and it works, which means the problem should be the if statement ?
I updated and it looks like that now, idk if I did it right
Yes, then I'm fairly confident of what is wrong.
void Update(){
if (Mathf.Approximately(point, Player.position.x)) // if the random point and player pos are at the same place
{
QuestionZone.SetActive(true); // display panel
Time.timeScale = 0f; //block movement
qsPaused = true; // and ask a question
}
}
post your entire script in a link from this site https://gdl.space
I have an idea
tell me
point is always ahead of player.position.x
and point is a float
if (point - player.position.x <= 0f)
However
Or, I'm not sure this matters, but once the player reaches this point
the code within the if-statement will run every single frame
so you can add the following
if (QuestionZone.activeInHierarchy == false && point - player.position.x <= 0f)
if (!QuestionZone.activeInHierarchy && point - player.position.x <= 0f)
where do I add them
I mean change the if-statement
there is only one example
but the second line is a shorter way of writing == false
You're welcome. I have to go soon.
Good stuff. You're welcome.
Have a nice day :)
Have a nice day too !
PS:
(point - player.position.x <= 0f)
This means it only works in one direction
If you want to adapt it, you might need to get creative.
ahaha yeah i got it thank you so much
Hi again @rapid vault 🥲
Hello. Is this related to the same issue?
Well more or less
So I have like my csv file that is now in my unity script and all, and now I want to use a random Country (so "Pays" in the script)
Like, I want to call it, but in another script, but idk how
So this is the script with the csv file loaded in:
public class LoadQuestion : MonoBehaviour
{
List<Titres> Questions = new List<Titres>();
void Start()
{
TextAsset Country = Resources.Load<TextAsset>("Country");
string[] data = Country.text.Split(new char [] {'\n'});
for (int i = 1; i < data.Length - 1; i++)
{
string [] row = data[i].Split(new char[] {','});
Titres q = new Titres();
q.Pays = row[0];
q.Capitale = row[1];
Questions.Add(q);
}
}
}
And then this is the script where I want to call a random "Pays"
LoadQuestion loadquestion;
[SerializeField] GameObject Box;
void Start()
{
loadquestion = Box.GetComponent<LoadQuestion>();
I'm not familiar with the lists in c# but I've worked with python lists at school
For new questions, you need to post like everybody else in the channel. (rules)
I'm busy right now anyway :)
This is part of what you're looking for
https://www.youtube.com/results?search_query=unity+reference+between+scripts