Page 1 of 1

Randomize Response Positions

Posted: Mon Jan 22, 2018 2:11 am
by Craftytroll
Hello,

First time using the forum so bear with me!

I am trying to randomize the response menu when I display a set of dialogue options and can't seem to figure out how to do it.

I want to do this so that if the player has played through the game once he would not be able to select the dialog in the same position to get the correct response again.

Ex
First play through
1. Dialog#1
2.Dialog#2
3.Dialog#3

Second playthrough
First play through
1. Dialog#2
2.Dialog#1
3.Dialog#3

Thanks!

Re: Randomize Response Positions

Posted: Mon Jan 22, 2018 7:59 am
by Tony Li
Hi,

Welcome to the forum!

You can add this script to your Dialogue Manager. It will shuffle the response menu:

ShuffleResponses.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

// Add this script to the Dialogue Manager or one of the conversation participants
// to shuffle the responses that will be shown in the player response menu.
public class ShuffleResponses : MonoBehaviour
{
    void OnConversationResponseMenu(Response[] responses)
    {
        for (int t = 0; t < responses.Length; t++)
        {
            var temp = responses[t];
            int r = Random.Range(t, responses.Length);
            responses[t] = responses[r];
            responses[r] = temp;
        }
    }
}
Here's an example scene that contains the script: QuizExample_2017-05-21.unitypackage

It also contains an example of randomly generating numbers for a math quiz.

Re: Randomize Response Positions

Posted: Wed Jan 31, 2018 5:59 pm
by Craftytroll
Thank you so much that worked great!

Re: Randomize Response Positions

Posted: Wed Jan 31, 2018 6:54 pm
by Tony Li
Great! Happy to help!