Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by sellar · Sep 23, 2016 at 02:36 AM · menu screen

My object menu appears only for 1 second

Hi there,

I have a bit of a script error...

When I roll my reticle over an object for which I want a menu to appear, the menu appears only for a flash of time, then disappears. Please help with what is wrong with my script! Thank you :)

using UnityEngine; using System.Collections; using VRStandardAssets.Utils; using UnityEngine.UI;

public class MenuHandler : MonoBehaviour {

 public enum MenuFunctions {ExitMenu, PickUp, Drop, Create, Duplicate, Destroy};

 public GameObject m_Player;
 public GameObject m_MainMenu;
 public GameObject m_CreationMenu;
 public Image m_ReticleOut;
 public Image m_ReticleOver;
 //public NavMeshAgent m_Agent;
 public GameObject m_ObjMenu;

 bool isEnabled = false;
 private GameObject m_CurrentObject;
 private float m_SpawnHeight = 2.0f;

 private Transform m_ItemHolder;
 private Transform m_Interactables;
 private GameObject m_MenuHolder;
 private GameObject m_ObjMenuHolder;
 private GameObject m_ObjMenuCanvas;
 private bool m_IsPickedUp = false;
 private bool m_IsDropped = false;
 private bool m_ObjMenuActive = false;


 void Start()
 {
     m_ItemHolder = GameObject.Find("ItemHolder").transform;
     m_Interactables = GameObject.Find("Interactables").transform;
     m_MenuHolder = GameObject.Find("VRInterface");
     m_ObjMenuHolder = GameObject.Find("ObjMenuTransform");
     m_ObjMenuCanvas = GameObject.Find("ObjMenuCanvas");
 }

 void Update()
 {
     transform.position = m_Player.transform.position;
     transform.eulerAngles = new Vector3(0, Camera.main.transform.eulerAngles.y, 0);
 }

 public void ToggleMenu()
 {
     isEnabled = !isEnabled;
     if(m_MainMenu != null)
         m_MainMenu.SetActive(isEnabled);
     if (m_CreationMenu != null)
         m_CreationMenu.SetActive(false);
 }

 public void DisableMenu()
 {
     isEnabled = false;
     if (m_MainMenu != null)
         m_MainMenu.SetActive(isEnabled);      
 }

 public void MenuFunc(MenuFunctions mode)
 {
     switch(mode)
     {
         case MenuFunctions.ExitMenu:
             DisableMenu();
             m_ReticleOut.enabled = true;
             m_ReticleOver.enabled = false;
             break;
         case MenuFunctions.PickUp:
             //PICK UP this object   
             //Debug.Log("Pickup");
             if (m_CurrentObject != null)
             {
                 //Debug.Log("Object not empty");
                 if (m_ItemHolder.childCount == 0)
                 {
                     //Debug.Log("Hands are empty");
                     m_ObjMenuCanvas.transform.GetChild(0).gameObject.SetActive(false);
                     m_ObjMenuActive = false;
                     m_CurrentObject.GetComponent<Rigidbody>().isKinematic = true;
                     m_CurrentObject.transform.SetParent(m_ItemHolder);
                     m_CurrentObject.transform.localPosition = new Vector3(0, 0, 0);
                     m_IsPickedUp = true;
                 }
             } 
             m_ReticleOut.enabled = true;
             m_ReticleOver.enabled = false;
             break;
         case MenuFunctions.Drop:
             //PICK UP this object   
             //Debug.Log("Drop");
             if (m_CurrentObject != null)
             {
                 //Debug.Log("Object not empty");
                 if (m_ItemHolder.childCount == 0)
                 {
                     //Debug.Log("Hands are empty");
                     m_ObjMenuCanvas.transform.GetChild(0).gameObject.SetActive(false);
                     m_ObjMenuActive = false;
                     m_CurrentObject.GetComponent<Rigidbody>().isKinematic = true;
                     m_CurrentObject.transform.SetParent(m_ItemHolder);
                     m_CurrentObject.transform.localPosition = new Vector3(0, 0, 0);
                     m_IsDropped = true;
                 }
             }
             m_ReticleOut.enabled = true;
             m_ReticleOver.enabled = false;
             break;
         case MenuFunctions.Create:
             if (m_MainMenu != null)
                 m_MainMenu.SetActive(false);
             if (m_CreationMenu != null)
                 m_CreationMenu.SetActive(true);
             m_ReticleOut.enabled = true;
             m_ReticleOver.enabled = false;
             break;
         case MenuFunctions.Duplicate:
             Vector3 trans = m_CurrentObject.transform.position;
             trans += new Vector3(0, m_SpawnHeight, 0);
             Instantiate(m_CurrentObject, trans, m_CurrentObject.transform.rotation);
             break;
         case MenuFunctions.Destroy:
             if(m_ObjMenu != null)
                 m_ObjMenu.SetActive(false);
             Destroy(m_CurrentObject, 0.1f);
             break;
     }
 }

 public void SetCurrentObject(GameObject curr)
 {
     m_CurrentObject = curr;
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

70 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A shared in-game hud for all scenes/levels 0 Answers

Options menu won't work 0 Answers

How to create scene with multiple panels? 0 Answers

Disable 3rd person controller when menu's are active 0 Answers

Creating and organizing Game Menu and Level Menu 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges