Trying to create selectable objects

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jrose1184
Posts: 16
Joined: Mon Jan 22, 2024 2:35 pm

Trying to create selectable objects

Post by jrose1184 »

Hi,

I’m having an issue of how to achieve this with your system.

So what I want to do is after I completed a task I can select a weapon.

So at the moment I am firing an event to activate a game object that allows me to navigate on the weapons.

This all works fine.

But my issue is I want to give each weapon a descripton but the text just currently stays on the last description I added for that dialogue.(my last dialogue node)

So I thought maybe I could add 5 child nodes for 5 weapons and through code set the variable to active and the rest to false.

But the issue is I can’t go back. So for instance the parent node says “please select a weapon’ There are 5 child nodes with the weapon description on that.

Well I don’t want to set that to false because it would require me A to press continue or B it would go back to please select a weapon again.


It’s like I want a wheel of logic that never goes back to the please select a weapon.

Hope this makes sence.
jrose1184
Posts: 16
Joined: Mon Jan 22, 2024 2:35 pm

Re: Trying to create selectable objects

Post by jrose1184 »

So ideally when I press up and down on the keyboard the dialogue would change the description like a loop without going back to the main parent.
User avatar
Tony Li
Posts: 21634
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to create selectable objects

Post by Tony Li »

Hi,

I'm not sure I understand what you mean. Can you provide a screenshot or sketch?

If it isn't something that the Dialogue System provides, you may need to write a little code.
jrose1184
Posts: 16
Joined: Mon Jan 22, 2024 2:35 pm

Re: Trying to create selectable objects

Post by jrose1184 »

Hi,

Sorry i'm not very good at explaining lol.

Image
https://ibb.co/Hg9Kd8Y

So here is my Conversation tree. What i was trying to do here i make a conversation for each weapon with a bool, but of course this would never work asit can't go between each weapon dialouge.

Image
https://ibb.co/J33fqy2

Here is my weapon select screen. So what happens is when the converstaion starts, on the sword weapon i set the sequence to Camera(CameraAngle,,1);
@{{end}} that sets the camera where i want it to go. I set the condtion to Variable["Axe"] == true and then i set a scene event on the game object to active so it runs my code ill paste the code any way for you

Code: Select all

using UnityEngine;

public class WeaponSelector : MonoBehaviour
{
    public GameObject[] objects; // Assign your 5 GameObjects in the Inspector
    private int currentIndex = 0;

    // These values control the scaling and rotation effect
    public float scaleMultiplier = 0.6f; // Scale for the selected object
    public float normalScale = 0.511811f; // Normal scale for unselected objects
    public float rotationSpeed = 20f; // Speed of rotation for the selected object

    private Vector3[] originalPositions; // Store original positions
    private Vector3[] originalScales; // Store original scales
    private Quaternion[] originalRotations; // Store original rotations

    private void Start()
    {
        PlayerController.instance.gameObject.SetActive(false);
        // Store original positions, scales, and rotations of all objects
        originalPositions = new Vector3[objects.Length];
        originalScales = new Vector3[objects.Length];
        originalRotations = new Quaternion[objects.Length];

        for (int i = 0; i < objects.Length; i++)
        {
            originalPositions[i] = objects[i].transform.localPosition;
            originalScales[i] = objects[i].transform.localScale; // Store the original scale
            originalRotations[i] = objects[i].transform.localRotation; // Store the original rotation
        }
    }

    private void Update()
    {
        HandleInput();
        UpdateSelection();
    }

    private void HandleInput()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            currentIndex = (currentIndex - 1 + objects.Length) % objects.Length;
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            currentIndex = (currentIndex + 1) % objects.Length;
        }
    }

    private void UpdateSelection()
    {
        // Define how far back the object should be from the camera
        float zOffset = 2.5f; // Adjust this value as needed

        // Calculate the center position based on the camera's viewport
        Vector3 centerPosition = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, zOffset));

        for (int i = 0; i < objects.Length; i++)
        {
            if (i == currentIndex)
            {
                // Move the selected object to the center of the screen
                objects[i].transform.position = centerPosition; // Center position
                objects[i].transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); // Scale for selected object
            
                // Rotate the selected object continuously
                objects[i].transform.Rotate(0, 0, rotationSpeed * Time.deltaTime);
            }
            else
            {
                // Reset the position, scale, and rotation of unselected objects
                objects[i].transform.localPosition = originalPositions[i];
                objects[i].transform.localScale = originalScales[i]; // Reset to original scale
                objects[i].transform.localRotation = originalRotations[i]; // Reset to original rotation
            }
        }
    }


} 
So this just allows me to use the arrow keys up and down so i can select a weapon.

What i want im trying to do is update the text to match the weapon

so i.e sword the npc would say "the sword" then i press either up or down and it would say "the bat" etc....

But i'm just not sure how to achive this. with this conversation tree - other then maybe swapping the text out with code?

here is my weapon selector just to show you what i see

Image
https://ibb.co/9T0v8d7

I hope that ma
User avatar
Tony Li
Posts: 21634
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to create selectable objects

Post by Tony Li »

Hi,

Inspect The Axe, The Bat, etc., and set the Actor dropdowns to Player.

This will show the weapons in a response menu that the player can choose from.

Then inspect the Dialogue Manager GameObject's Input Device Manager component and tick Always Auto Focus. This will allow you to navigate them using the keyboard or joystick.
jrose1184
Posts: 16
Joined: Mon Jan 22, 2024 2:35 pm

Re: Trying to create selectable objects

Post by jrose1184 »

Thank you so much!
User avatar
Tony Li
Posts: 21634
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to create selectable objects

Post by Tony Li »

Glad to help!
Post Reply