I have a menu Unity UI prefab:
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).
It looks like you're new here. If you want to get involved, click one of these buttons!
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;
}`
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:
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:
@ChrisIceBox It worked thank you!