- Home /
Problem with a Unity tutorial
Hi, i´m trying to do something like this video: https://www.youtube.com/watch?v=_ijhS6aezQc But i´m not using all these variables and always i receive the same error:
NullReferenceException: Object reference not set to an instance of an object CreateScrollList.PopulateList () (at Assets/Scripts/MainMenu/CreateScrollList.cs:29) CreateScrollList.Start () (at Assets/Scripts/MainMenu/CreateScrollList.cs:21)
The problem is when i tried to get the sample button, i don´t know why, could some one help to me? I put in strong the problem.
Here is my CreateScrollList. Thank you so much!
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System.IO;
[System.Serializable]
public class Item {
public string name;
public Button.ButtonClickedEvent thingToDo;
}
public class CreateScrollList : MonoBehaviour {
public GameObject sampleButton;
public List<Item> itemList;
public Transform contentPanel;
void Start () {
PopulateList ();
}
void PopulateList () {
itemList = getFiles ();
foreach (var item in itemList) {
GameObject newButton = Instantiate (sampleButton) as GameObject;
**SampleButton button = newButton.GetComponent <SampleButton> ();
button.nameLabel.text = item.name;**
newButton.transform.SetParent (contentPanel);
}
}
public List<Item> getFiles(){
...
}
Comment
Your answer

Follow this Question
Related Questions
Moving platform not taking mesh with it 0 Answers
3D Platformer Tutorial - 5 Answers
3D Platform Tutorial Problem 1 Answer
Lerpz tutorial problems 2 Answers