Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Dec 01, 2014 at 12:13 PM by Josh Naylor for the following reason:

Duplicate Question

avatar image
0
Question by CJGames · Dec 01, 2014 at 12:12 PM · javascriptfpsinstancehealth

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

Comment
Comments Locked
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges