How do I call a variable from another script? (C#)
Hi, I'm trying to call a variable from another script, this variable is inside of a namespace., so I'm having trouble to archieve this.
THE SCRIPT TRYING TO ACCESS THE VARIABLE:
using System;
using UnityEngine;
[RequireComponent(typeof(UnityFunction.Class_One))]
public class Class_Two : MonoBehaviour {
private UnityFunction.Class_One the_other_var; public string the_string;
void Start()
{
the_other_var = GetComponent<Tractor_Speed> ();
}
void Update()
{
the_string = the_other_var.the_var;
}
}
THE SCRIPT WITH THE VARIABLE:
using System;
using UnityEngine;
namespace UnityFunction {
public class Class_One : MonoBehaviour {
public string the_var;
void Start()
{
the_var = "Hi";
}
}
}
Answer by UnityCoach · Dec 05, 2016 at 11:21 PM
You can add a using statement at the beginning of the script, like
using UnityFunction;
Can you share the error message you get?
I found a solution, thanks for your interest. I had to associate the variable to an object before I could get it's value.
Your answer
Follow this Question
Related Questions
How to get all the variables in a folder. C# 0 Answers
Animator Parameter not linking to script variable 0 Answers
Way of Finding/accessing a variable from another script though another variable? 1 Answer
Vector3 variable not changing 0 Answers
Changing a variable in another script on Raycast hit - C# 1 Answer