- Home /
Duplicate Question
An instance of type (Script) is required to access non static member (Script)
-JAVASCRIPT-
Well, first of all, sorry about my english, hope you can understand and answer, but let's go. I'm making an FPS and I have an Ammo Box, and an MedKit, but i'm having problens with the MedKit, the scripts are the same (with names and variable changes), and the error (i think) is that my script (called "Recharger-Health", added to my MedKit) can't reach my other script (called "CharacterHealth", added to my Player) to add heath when i press E and the distance between me and the box is lower than 2. Here's my AMMO BOX CODE (Wich is WORKING just fine):
#pragma strict
//Ammo Box/Recharger script
var distBox : int;
var rechargeQuant : int;
var skinAmmo : GUISkin;
function Start () {
rechargeQuant = 225;
}
function Update () {
distBox = Vector3.Distance(GameObject.Find("Player").transform.position, transform.position);
if(Input.GetKeyDown(KeyCode.E) && distBox <= 2){
Arma.mags = Arma.mags + 225;
Destroy(gameObject);
}
}
function OnGUI(){
GUI.skin = skinAmmo;
if(distBox <=2){
GUI.Label(Rect(Screen.width /2 -150,Screen.height /2,500,500), "Press E to recharge your gun");
}
}
And here's my MEDKIT CODE (Wich is not working):
#pragma strict
//MedKit script
var distBox : int;
var rechargeQuant : int;
var skinHealth : GUISkin;
function Start () {
rechargeQuant = 50;
}
function Update () {
distBox = Vector3.Distance(GameObject.Find("Player").transform.position, transform.position);
if(Input.GetKeyDown(KeyCode.E) && distBox <= 2){
CharacterLife.totalHealth = CharacterLife.totalHealth + 50;
Destroy(gameObject);
}
}
function OnGUI(){
GUI.skin = skinHealth;
if(distBox <=2){
GUI.Label(Rect(Screen.width /2 -150,Screen.height /2,500,500), "Press E to heal yourself");
}
}
(Removed some spaces to make it smaller)
Well, and the error I get is in the part: CharacterLife.totalHealth = CharacterLife.totalHealth + 50;
Here's the error:An instance of type "CharacterHealth" is required to acess non static member "totalHealth"
CharacterHealth is my health script, attatched to my Player, and totalHealth is the current health variable inside this script.
The only difference between "Recharger-Ammo" and "Recharger-Health" is that "Characterhealth" (Acessed by "Recharger-Health") is inside Player, and "Arma"(Gun in english, acessed by "Recharger-Ammo") is inside "ARMA"(Gun in english, arma is inside Main Camera that is inside Player, and "Arma" script is attatched to it).
Well, can somebody help me? Thanks a LOOOT! :D
Follow this Question
Related Questions
Looking for skilled individual to assist with problem 1 Answer
Health not counting down? 1 Answer
Make Body go limp after dead 1 Answer
Health Script 1 Answer
health script will not work 2 Answers