Bring class variable into other class

Hi everyone, Im stuck on how to implement this variable from one class to another in my code. I want to have my Combination from my Keypad class equal the password from my Item class. The reason why I want to do this is because this password you find within the game will be the combination you need to put in the keypad. Heres the script:

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

public class RayCasting : MonoBehaviour
{
	public float pickupDistance;
	public List<Item> items;
	public List<Keybutton> buttons;

	#region Unity
	void Start ()
	{
		Screen.lockCursor = true;

		for (int i = 0; i < items.Count; i++) {
			Item temp = items*;*
  •  	int randomIndex = Random.Range(i, items.Count);*
    

_ items = items[randomIndex];_
* items[randomIndex] = temp;*
* }*
* }*
* void Update ()*
* {*
* RaycastHit hit;*
* Ray ray = new Ray(transform.position, transform.forward);*
* if (Physics.Raycast(ray, out hit, pickupDistance))*
* {*
* foreach(Item item in items)*
* {*

* if(Input.GetMouseButtonDown(0)) {*
* if (item.gameObject.Equals(hit.collider.gameObject))*
* {*
* numItemsCollected++;*
* item.Collect();*
* break;*
* }*
* }*
* }*

// This is for the KeyPad Buttons Area

* foreach(Keybutton button in buttons)*
* {*

* if(Input.GetMouseButtonDown(0)) {*
* if (button.gameObject.Equals(hit.collider.gameObject))*
* {*
hit.transform.renderer.material.color = Color.red;
* button.ButtonWasClicked(button.currentCombination);*
* break;*
* }*
* }*
* }*

* }*
* }*

Here is where the issue may start. This class is the Item class which calls in the Collect variables and password.

[System.Serializable]
public class Item
{
* public string name;*
* public GameObject gameObject;*
* public int password;*

* public bool Collected { get; private set; }*

* public void Collect()*
* {*
* Collected = true;*
* //gameObject.SetActive(false);*
* }*

* public void passwordNumber()*
* {*
* password = 0;*
* Collected = true;*
* gameObject.SetActive(false);*
* }*

}
This here could be another issue, as this is the Keybutton class. This is where the gameObject button are assigned numbers 0-9 through the currentCombination. The thing is that we want the Combination to equal the password we find in the Item class. Once we find the password, we go put in the currentCombination, and if its correct Combination it should say correct passcode, other wise wrong passcode.
[System.Serializable]
public class Keybutton
{
* public GameObject gameObject;*
* //public int Numberbutton;*
* private int Combination;*
* public int currentCombination;*
* public int buttonClickProgress;*

* public void ButtonWasClicked (int buttonNmb){*
* Item item = new Item ();*

* Combination = item.password;*
* buttonClickProgress+=0;*
* currentCombination = buttonNmb;*

* if(buttonClickProgress < 10){*
* decimal d = (decimal)currentCombination / 10;*
* Debug.Log(currentCombination);*
* }*
* else{*
* if(currentCombination == Combination){*
* Debug.Log(“Correct Passcode”);*
* buttonClickProgress = 0;*
* currentCombination = 0;*
* }*
* else{*
* Debug.Log(“Wrong Passcode, reseting…”);*
* buttonClickProgress = 0;*
* currentCombination = 0;*

* }*
* }*
* }*
}
So to recap I was wondering how to get the Combination variable to equal the passcode, so once we put in the currentCombination it should equal the Combination which is equal to the passcode you find.

how to implement this variable from one class to another in my code

You are already doing it:

 public void  ButtonWasClicked (int buttonNmb){
        Item item = new Item ();
 
        Combination = item.password;

But it seems you are trying to achieve it by brute force, since you are creating a new item and assigning its blank value to the combination, and then you don’t actually use it. Looking at your other questions you are simply making code and mixing it together, expecting it will work:

So you need to isolate each problem, solve it and understand how it works. Then you can bring the solution to your main project, not by copy-pasting, but re-writing what you understood. For example, if you need to understand how to detect an object with Raycast, do only that in a new project. If you need to understand how to register a sequence of buttons being pressed, simulate the touches with something simple like GUI buttons, and focus on building the sequence in a string. Then create a new test to get the password string from the class that receives that input, into the manager class that uses it to control the game logic. Emulate everything that is not part of the small problem you are trying to solve.