C#C
C#3y ago
93 replies
AdiZ

Absolute Beginner - Accessing Variables From Other Classes

Hi.
DecodeButton.cs:
using UnityEngine;

public class DecodeButton : MonoBehaviour
{
    void Start()
    {
        Decoders decoder = new Decoders();
    }

    void OnClick()
    {
        Decoders.CaesarCipher(ReadStringInput.input);
    }
}


ReadStringInput.cs:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReadStringInput : MonoBehaviour
{
    public string input;
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void ReadInput(string s)
    {
        input = s;
    }
}


In DecodeButton.cs, I'm getting the error CS0120 about Object references but frankly I'm not understanding it. Can someone help me out?
Was this page helpful?