- Home /
Getting static variable from another C# script using C#
I've read other post about this, I try to follow the same method but I keep getting an error. Here's the specific I have object name Projectile and Player
public class Projectile : MonoBehaviour {
public float ProjectileSpeed; public static float RELOADTIME = 0.05f; } In Player, I want to access RELOADTIME from Projectile. Here is what I did
public class Player : MonoBehaviour { public GameObject ProjectilePrefab; private float RELOADTIME; void Start () { ProjectileScript projectileScript = ProjectilePrefab.GetComponent(); RELOADTIME = projectileScript.RELOADTIME; }However, I keep getting this error Assets/Script/PlayerScript.cs(15,17): error CS0246: The type or namespace name `ProjectileScript' could not be found. Are you missing a using directive or an assembly reference?
I'm really frustrated :( I don't know what have I done wrong. Sorry, I'm a newbie in Unity. THANKS A LOT :(
It seems that UA has eaten the type in GetComponent...
Answer by DaveA · Aug 21, 2012 at 12:22 AM
Your class is called Projectile. Did you name the file its in Projectile or ProjectileScript? It should be the same name as the file.
$$anonymous$$y prefab named is Projectile. The script name is ProjectileScript. It still doesn't work when I change it to Projectile ins$$anonymous$$d
WoW never$$anonymous$$d. I see what you are saying. THAN$$anonymous$$S A LOT
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Unity Quits Because Of Script!!! 1 Answer
Why can't I change another script's variable with this script? Thanks, 1 Answer
Error CS0246 1 Answer