Quantcast
Channel: Latest Questions by MobiusDev
Viewing all articles
Browse latest Browse all 22

Problem with calling functions from other scripts.

$
0
0
I currently have damage script calling a function from another script which is called shields. I've fooowed this guys video (http://www.youtube.com/watch?v=nEMneTf2Wcs) but when i start the game i get "(20,36): BCE0020: An instance of type 'UnityEngine.GameObject' is required to access non static member 'GetComponent'." Here is the script i am pulling the function from. var maxShields = 100; var curShields = 100; function Start() { } function AdjustCurShields(adjustShields:int) { curShields += adjustShields; if (curShields>maxShields) curShields=maxShields; } function Update() { if (curShields<=0) Debug.Log("shields are down"); AdjustCurShields(0); } here is the script with the function i am calling from the other script. function Start () { } function Update () { if (Input.GetKeyUp(KeyCode.F)) { Attack(); } } function Attack() { var AdjCurShields : Shields; AdjCurShields = GameObject.GetComponent("Shields"); AdjCurShields.AdjustCurShields(-10); } Thanks in advance.

Viewing all articles
Browse latest Browse all 22

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>