SetActive canvas relative to selected object
I'm trying to SetActive the canvas relative to the position of selected gameobject. but canvas will always appear relative to the position of first object I attached the script to. here's an example script:
public GameObject menu;
public GameObject obj;
void Start()
{
menu.SetActive(false);
}
void OnSelect()
{
menu.SetActive(!menu.activeSelf);
menu.transform.position = obj.transform.position + obj.transform.up *0.5f;
}
not sure what went wrong. I drag all correct object accordingly but does not work properly. please help. thx a lot
The code there is fine, it's probably something else causing your errors.
i just realize the update is causing the problem. solved it without void Update. however, how do i have the menu to follow position of object when moving the object? seems like i cant have it in update.
Your answer
Follow this Question
Related Questions
SetActive is just working if i press twice in the first time 2 Answers
How to keep bool true even when other method try to set it off 0 Answers
gameObject.SetActive (false); Not working 0 Answers
Hide/Unhide Canvas in AR Project 0 Answers
UnityEngine.Component.gameObject' is a `property' but a `type' was expected 1 Answer