mercredi 14 septembre 2016

I cant figure out how to SetValue using reflections

i have been trying to use reflections for some time now and sadly my efforts lead me to errors, what i am trying to do is get the field of a integer from another script and change it, here is my code:

My first script

using UnityEngine;
using System.Collections;

public class GameInformation : MonoBehaviour 
{

    void Awake()
    {
        DontDestroyOnLoad(transform.gameObject);
    }

    //1 is bought while 0 is not bought
    public static int TipJar;
}

My Second Script

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic; 
using System;


public class Upgrades : MonoBehaviour 
{
    public GameInformation gio;

    void Start()
    {
        gio = GameObject.Find("lol").GetComponent<GameInformation>();

        Type myClassType = gio.GetType().GetField("TipJar").SetValue(gio, 1, null); //<-- Error
    }
}

Any ideas? Sorry for asking a nooby question i am still learning how to program and thanks in advance!





Aucun commentaire:

Enregistrer un commentaire