#Yes but sorting is different in runtime

1 messages · Page 1 of 1 (latest)

spring gazelle
#

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

rapid vault
#
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)

mint rover
#

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
        }
    }```
spring gazelle
rapid vault
#

You can test the conceptual solution, without any possible interference or derp from the expression logic

spring gazelle
#

ohh okay wait i'll go eat and then try it

#

thank you

mint rover
rapid vault
#

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)

mint rover
#

It would also be better to write the if with >= instead of ==. Just to prevent you overshooting for some reason.

rapid vault
#

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).

spring gazelle
#

I updated and it looks like that now, idk if I did it right

rapid vault
#

Yes, then I'm fairly confident of what is wrong.

spring gazelle
#
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
        }

    }
rapid vault
spring gazelle
#

okay wait

rapid vault
#

I have an idea

spring gazelle
#

tell me

rapid vault
#

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)
spring gazelle
#

where do I add them

rapid vault
#

I mean change the if-statement

#

there is only one example
but the second line is a shorter way of writing == false

spring gazelle
#

ohh okay okay let me try

#

thank you for your time

rapid vault
#

You're welcome. I have to go soon.

spring gazelle
#

don't worry

#

oh my-

#

thank you so much

#

it worked

#

thank you really

rapid vault
#

Good stuff. You're welcome.
Have a nice day :)

spring gazelle
#

Have a nice day too !

rapid vault
#

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.

spring gazelle
#

ahaha yeah i got it thank you so much

spring gazelle
#

Hi again @rapid vault 🥲

rapid vault
spring gazelle
#

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

rapid vault