Forum rules - please read before posting.

move position of menu using right click

I have a menu Unity UI prefab:

https://imgur.com/a/O0dH2Vd

I wish to make the position of the menu move by right clicking. I have a script attached to a camera. Here is what I have now:

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using AC;

public class ingameuitransition : MonoBehaviour
{
bool open = false;
private Vector3 openPosition = new Vector3(50, 50, 0);
private AC.MenuManager manager;
private AC.Menu ui;

void Start()
{
    ui = manager.GetMenuWithID(4);
    Debug.Log("start");
}

void Update()
{
    if (Input.GetMouseButtonDown(1))
    {
        Debug.Log("hello");
        //changed to return at next right click
        if (!open)
        { //same to: open == false
            open = true;
            Debug.Log(open);

        }
    }
}

}`

The script doesn't seem to want to take my getMenuWithID(4).

Comments

  • You're not assigning your "manager" variable.

    See the front page of the Scripting guide - the active Menu Manager can be referenced via:

    KickStarter.menuManager

    In order to move a UI Menu, be aware that you must place all the elements you wish to move into a shared hierarchy by making them all children of an object that is itself a child of the Canvas. Then assign this object as your Menu's "RectTransform boundary".

  • @ChrisIceBox

    Here is my new prefab all assigned:

    https://imgur.com/a/5p7mo2e

    And here is my new script

    `using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;
    using AC;

    public class ingameuitransition : MonoBehaviour
    {
    bool open = false;
    private Vector3 openPosition = new Vector3(50, 50, 0);
    AC.MenuManager manager;
    AC.Menu menu;

    void Start()
    {
        //ui = menumanager.GetSelectedMenu();
        manager = AC.KickStarter.menuManager;
        menu = manager.getMenuWithID(4);
    
        //Debug.Log(menumanager.get
    }
    
    void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            Debug.Log("hello");
            //changed to return at next right click
            if (!open)
            { //same to: open == false
                open = true;
                //menu.SetCentre3D(openPosition);
            }
        }
    }
    

    }`

    The manager is assigned alright but the AC.menu still wouldn't take getMenuWithID.

  • What are you attaching the script to? If it's on the UI prefab, you can retrieve the Menu class with the Canvas:

    public Canvas thisCanvas;
    
    private void OnEnable ()
    {
        menu = KickStarter.playerMenus.GetMenuWithCanvas (myCanvas);
    }
    

    Try this in OnEnable instead of Start. Bear in mind that this'll be run once when AC initialises, so you should do a null check in your Update method:

    if (menu != null && Input.GetMouseButtonDown (1))
    
  • @ChrisIceBox It worked thank you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.