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 xSyk · Jan 07, 2016 at 09:57 PM · unity5restartnull exception

Script not working after restart unity, giving null exception

So i made one script to fill a roulette based in enums. The enum items will be the roulette items. The script it's work fine but when i restart unity it just give me null execeptions and i need to reset the script. When i do it's working properly again. But when i restart Unity it's giving me the same error.

this is the script:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using System.Collections.Generic;
 
 [RequireComponent(typeof(EnumList))]
 public class RouletteUI : MonoBehaviour
 {
 
     internal enum RouletteDirection { UP = -1, DOWN = 1 };
 
     public List<Transform> _rouletteItemTransform;
     public GameObject _roulleteItemPrefab;
 
     System.Type m_T;
     public List<KeyValuePair<string, int>> m_Values;
     private int m_Index = 0;
 
     /// <summary>
     /// Describes the scroll amount in a given direction
     /// </summary>
     internal struct ScrollInfo
     {
         public float amount;
         public RouletteDirection _direction;
         public Vector3 _referencePosition;
         private Vector3 _lastPos;
 
         /// <summary>
         /// This method should be called when a drag action starts.
         /// </summary>
         /// <param name="pStartPosition"> is the mouse position at the beggining of the scroll action</param>
         public void BeginScrolling(Vector3 pStartPosition)
         {
             UpdateScrollAmount(pStartPosition);
             this._referencePosition = pStartPosition;
             this.amount = 0;
             this._direction = RouletteDirection.DOWN;
         }
 
         public void UpdateScrollAmount(Vector3 pMousePosition)
         {
 
             // are we changing direction ?
             if (pMousePosition.y > this._referencePosition.y && pMousePosition.y < this._lastPos.y)
             {
                 this._lastPos = this._referencePosition = pMousePosition;
                 this._direction = RouletteDirection.UP;
                 //Debug.Log("Direction changed! Now going UP.");
             }
 
             if (pMousePosition.y < this._referencePosition.y && pMousePosition.y > this._lastPos.y)
             {
                 this._referencePosition = pMousePosition;
                 this._direction = RouletteDirection.DOWN;
                 //Debug.Log("Direction changed! Now going DOWN.");
             }
 
             // Update the amount accordingly
             this.amount = this._referencePosition.y - pMousePosition.y;
             _lastPos = pMousePosition;
 
         }
     }
     public float _scrollSensitivity = 0.5f;
     public int _itemHeight = 30;
     public iTween.EaseType _animationType = iTween.EaseType.spring;
 
     private RectTransform _roulettePanel;
     private RectTransform _mainPanel;
     private RectTransform _selectorPanel;
     private ScrollInfo _scroll;
     private UnityEngine.EventSystems.EventTrigger _eventTrigger;
 
     // Selected element index
     private int selectedIndex = 4;
     private const string ROULETTE_PANEL_NAME = "RoulettePanel";
 
     public virtual void Start()
     {
         
         this._scroll = new ScrollInfo();
 
         // Find the roulette child panel
         _roulettePanel = transform.FindChild(ROULETTE_PANEL_NAME).GetComponent<RectTransform>();
 
         if (_roulettePanel == null)
             Debug.LogError(string.Format("Object '{0}' has no child named '{1}' with a RectTransform component attached to it", this.gameObject.name, ROULETTE_PANEL_NAME));
                 
         //Set all child element size to the desired one
         LayoutElement[] items = GetComponentsInChildren<LayoutElement>();
 
         foreach (LayoutElement e in items)
         {
             e.minHeight = e.preferredHeight = _itemHeight;
         }
 
         this._roulettePanel.transform.localPosition = Vector3.zero;
         InitializeRouleteItems();
     }
 
     public virtual void OnBeginDrag()
     {
     }
 
     public virtual void OnDrag()
     {
         this._scroll.UpdateScrollAmount(Input.mousePosition);
         ScrollRoulette(this._scroll);
     }  
     public virtual void OnEndDrag()
     {
     }
 
     private void ScrollRoulette(ScrollInfo pScrollInfo)
     {
         this._roulettePanel.Translate(Vector3.down * pScrollInfo.amount * _scrollSensitivity * Time.deltaTime);
 
     }  
 
     /// <summary>
     /// Instancia o prefab e cria os itens da roleta
     /// </summary>
     /// <param name="pText"></param>
     private void InstantiateRouletteItem(string pText)
     {
         GameObject item = Transform.Instantiate(_roulleteItemPrefab);
         item.transform.SetParent(_roulettePanel);
         item.GetComponent<Text>().text = pText;
 
         UnityEngine.UI.LayoutElement layout = item.AddComponent<UnityEngine.UI.LayoutElement>();
         layout.minHeight = _itemHeight;
         layout.preferredHeight = _itemHeight;
 
         _rouletteItemTransform.Add(item.transform);
     }
 
     protected void InitializeRouleteItems()
     {
         for (int i = 0; i < m_Values.Count; i++)
         {
             InstantiateRouletteItem(m_Values[i].Key);
         }
     }
 
     /// <summary>
     /// 
     /// </summary>
     /// <typeparam name = "T" ></ typeparam >
     public void InitializeWithEnum<T>() where T : System.IConvertible
     {
 
         if (!typeof(T).IsEnum) throw new System.ArgumentException("T must be an enumerated type");
 
         m_Values = new List<KeyValuePair<string, int>>();
         System.Array values = System.Enum.GetValues(typeof(T));
 
         foreach (object value in values)
         {
             string name = System.Enum.GetName(typeof(T), value);
             m_Values.Add(new KeyValuePair<string, int>(name, (int)value));
         }
         print("Selected Value" + GetSelectedString() + " : " + GetSelectedValue());
     }
 
     private int GetSelectedValue()
     {
         return m_Values[m_Index].Value;
     }
 
     private string GetSelectedString()
     {
         return m_Values[m_Index].Key;
     }
 }


So someone can help me with this?

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

40 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

Related Questions

who own a game made by unity 1 Answer

Material doesn't have a texture property '_CameraDepthTexture' 0 Answers

How to move forward (towards z), ignoring any rotations? 0 Answers

webgl app is not working in browser 0 Answers

Cloud build with google play games give me an error 0 Answers


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