using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TechButton : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
that one is added to prefab of button so each button has it.
on another game object named controller there is researchController script which needs to call every button from list of spawned buttons like this
for (int i = 0; i < techButtons.Count; i++)
{
techButtons[i].GetComponent<TechButton>().UpdateButton();
}
techButtons is list of List and it just doesnt recognize TechButton class from anywhere on script like any other script, why i cant access it as it worked before just fine.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TechButton : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void UpdateButton(){
// do something here
}
}
also… you should never assume something is there…
for (int i = 0; i < techButtons.Count; i++)
{
if(techButtons[i] != null){
var button = techButtons[i].GetComponent<TechButton>();
if(button != null){
button.UpdateButton()
}
}
lastly… I would not store gameObjects, when all you ever need is a monobehaviour from that object…
public TechButton[] techButtons;
it shortens the processing needed to get each element as you go, making your game just a touch faster.
Yeah, problem is that program doesnt recognise TechButton. Its marked red. Says it couldnt find it. Also intellisense doesnt recommend it but does others.
Try all the standard fixes first. Reimport the script in Unity. Restart Unity. Make sure the script name matches the class name. (Script name is TechButton and not techButton or something like that). Those would be the first things I’d try.
Sorry for inconvinience. Restarting unity fixed it. When quitting it asked me to save name of my project. Maybe saved my solution or something. Anyway thanks for the help