Random without objects fall to the same places #HELP

Hi, I shall need help for a script that I find no help(assistant) somewhere else:
make a system of random without objects fall to the same places.

But nobody few to help me :cry: I really need help.
Thank you for your answer.

You didn’t post anything, so how can we help you? What have you tried already? Show us some code and we can help you along if it’s not working the way you want. Most people aren’t just going to just write a script for you. (many reasons for this)

1 Like

Indeed… One small tidbit of help might be, once you try a script and you don’t want something to be at the same location, you can execute a small sphere/cube cast or something similar to ensure that no other object is present.
In case you have like 20 different “spots”, for example, but only 10 objects you place randomly, you could simply remove each “spot” from the list, and take a new random one, thus ensuring that any previously chosen spot is not re-used.
:slight_smile:

Ho, sorry. Then my project is when I press a button, GameObjects puts itself on the points of appearances without they are on the same place (For example: the distribution of cards).

I want that my GameObject mixes with the other GameObjects but without they are on the same place. For me it is impossible to make a script like that, but I really need it. Thank you if you find solution to my problem.

Here is I tried that but that does not work, my GameObject do not want to move. :cry:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Randomcard : MonoBehaviour {

        public Transform[] spawns;
        public GameObject Bone;
        public int amountThings = 2;
        public int i = 0;


        void Start()
        {
            Spawn();
        }


        public void Spawn()
        {
            List<Transform> freeSpawnPoints = new List<Transform>(spawns);
            for (i = 0; i < amountThings; i++)
            {
                if (freeSpawnPoints.Count <= 0)
                    return; // Not enough spawn points
                int index = Random.Range(0, freeSpawnPoints.Count);
                Transform pos = freeSpawnPoints[index];
                freeSpawnPoints.RemoveAt(index);
                Instantiate(Bone, pos.position, pos.rotation);
            }
        }

}

I am sorry for my bad english :slight_smile:

That looks more or less right to me.
So, what happens with this code? Does it instantiate a new object, but the position it goes to isn’t correct?

So, as soon as I press the button to execute the script, it GameObject do not want to move on points planned.

I want a script which allows GameObjects to move on 4 points, everything in random and without they are in the same places.

I’m not sure if you answered my question or not, sorry.

I answered your question. The problem it is that texts “Bonjour1”, “Bonjour2”, “Bonjour3” and "Bonjour4 "do not want to mix and to move on points “sp “,” sp (1) “,” sp (2) " and " sp (3)”, without texts are all in the same places.

Well, okay… You have 1 object you’re instantiating in the code.
The loop runs twice, again in your code, unless the value of ‘2’ was changed to 4 in the inspector.

But other than that, assuming that your positions are correctly set, your code looks good.
So, I was trying to talk through about where the issue is. :slight_smile:

I does not understand, you could make an example? Because I am French and I does not understand quite the themes in English, thanks to you :slight_smile:

Here, try this:

public void Spawn()
        {
            List<Transform> freeSpawnPoints = new List<Transform>(spawns);
            for (i = 0; i < amountThings; i++)
            {
                print("Loop #: " + i);
                if (freeSpawnPoints.Count <= 0)
                    return; // Not enough spawn points
                int index = Random.Range(0, freeSpawnPoints.Count);
                Transform pos = freeSpawnPoints[index];
                freeSpawnPoints.RemoveAt(index);
                print("Random position selected: " + pos.position);
                Instantiate(Bone, pos.position, pos.rotation);
            }
        }

Look at the logs in the console.

Did that help? I mean, is that where they went? those positions listed there?

No they did not move :frowning:

I’m desperate :cry:

Alright, well if you can make a simple package with just this little bit we’re talking about. You can post it here and I will download it and take a look at it and see what’s wrong, if you’d like.
You can post the unity package right on the forums.
If that fails for any reason, you can zip it and upload it to dropbox or onedrive, and paste the link.
I might see it tonight or tomorrow. Unless you get some help that fixes your issue, I’m not sure what else to say.

It is good, I put the file as attachment :slight_smile:

3121778–236310–Test-random.unitypackage (60.9 KB)

I’m checking it out now.

I forgot to explain, but the script I do not know where to put him(it)