Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Calling functions from other scripts with objects

$
0
0
I am aware this is everywhere however my question is a little more specific to objects. The issue i have is the code that is being called has assigned objects to it, the only way i could get it to work was to add "static var" to my 'var's', however on my unity client it won't let me assign the objects to it. Script 1: #pragma strict import UnityEngine.UI; static var player_hp : float = 0; static var hp_value_player : String =""; static var player_damage_red_range : boolean = false; static var player_damage_blue_range : boolean = false; static var myText : Text; function Start () { } function Update () { } static function hp_player() { player_damage_red_range = false; if (myText != null) { player_hp = float.Parse(myText.text); } } static function dot_damage() { player_hp -= Time.deltaTime * 1; hp_value_player= player_hp.ToString(); myText.text = player_hp.ToString("f0"); << Error is here (It is trying to modify a text however the unity client won't let me link them) } Script 2 (The script that is calling from another) function OnTriggerStay (trigger_red : Collider) { //yield WaitForSeconds (3); if (player_damage_red_range == true) { player_health.dot_damage(); << Line where its calling } } New to calling functions from other scripts. Any help is appreciated Thanks

Viewing all articles
Browse latest Browse all 1875

Trending Articles



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