Search Unity

Trying to Invoke method: LoadGameData.Load Data couldn't be called.

Discussion in 'Scripting' started by unity_MPhbdR7wb7LlCQ, Jan 25, 2021.

  1. unity_MPhbdR7wb7LlCQ

    unity_MPhbdR7wb7LlCQ

    Joined:
    Sep 14, 2019
    Posts:
    15
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Xml;
    5.  
    6. public class LoadGameData : MonoBehaviour
    7. {
    8.  
    9.  
    10.     public TextAsset GameData;
    11.  
    12.     public void Start()
    13.     {
    14.  
    15.  
    16.         Invoke("Load Data", .1f);
    17.     }
    18.  
    19.     public void LoadData()
    20.     {
    21.  
    22.         XmlDocument xmlDoc = new XmlDocument();
    23.  
    24.         xmlDoc.LoadXml(GameData.text);
    25.  
    26.         XmlNodeList StoreList = xmlDoc.GetElementsByTagName("store");
    27.  
    28.         foreach (XmlNode StoreInfo in StoreList)
    29.         {
    30.  
    31.             Debug.Log(StoreInfo.Name);
    32.             Debug.Log(StoreInfo.InnerText);
    33.  
    34.         }
    35.  
    36.     }
    37.  
    38.  
    39. Second code:
    40.  
    41. <gamedata>
    42.   <store>
    43.         <name>Rusted</name>
    44.         <BaseStoreCost>2</BaseStoreCost>
    45.   </store>
    46.   <store>
    47.       <name>Silver</name>
    48.       <BaseStoreCost>10</BaseStoreCost>
    49.   </store>
    50. </gamedata>
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    This is why Invoke is bad. No compile time checking.
    Invoke is looking for Load Data, which you couldn't have since methods can't have spaces in the method name. Make sure they match.

    LoadData vs Load Data
     
    unity_MPhbdR7wb7LlCQ likes this.
  3. unity_MPhbdR7wb7LlCQ

    unity_MPhbdR7wb7LlCQ

    Joined:
    Sep 14, 2019
    Posts:
    15
    Thanks, it worked