Quantcast
Channel: Latest Questions by hixon33
Viewing all articles
Browse latest Browse all 8

code refernce on specific instance

$
0
0
So I have some code (lets say codeA) referencing a static variable (var) in a separate code (codeB). CodeB is applied to multiple instances. CodeA changes var and then a function in codeB is started. My problem is that I want that function to happen only in whatever instance is being affected currently, but instead it starts the function on all the instances the code is applied to. CodeA: var attack: int = 20; var enemy: GameObject; var enemyHealth: EnemyHealth; function Awake () { enemyHealth = GetComponent(EnemyHealth); } function OnTriggerEnter(obj: Collider) { if(obj.gameObject.GetComponent(EnemyHealth)) { enemyHealth.currentHealth = enemyHealth.currentHealth - attack; } } CodeB: var startingHealth: int = 100; static var currentHealth: int; var enemy: GameObject; private var onDeath: PlayerMovement; private var anim: Animator; function Awake() { onDeath = GetComponent(PlayerMovement); currentHealth = startingHealth; anim = GetComponentInParent(Animator); } function Update() { if(currentHealth <= 0) { anim.SetBool("EnemyDeath", true); Destroy(enemy, 2); onDeath.enemyDie = true; } }

Viewing all articles
Browse latest Browse all 8

Trending Articles



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