Quantcast
Viewing all articles
Browse latest Browse all 1488

Attack/Targeting Script Issue

Hello! I have those two scripts below. What they basically allow me to do is to kind of attack an enemy if the mouse cursor is on the object. The issue here is when i have multiple enemies. For some reason i cannot attack whichever enemy i want and i have to start by killing the last one i placed in the scene :S Is there a way to fix this? Thanks! MeleeDamage.js var mDPS : int; var oDPS : int; function mainhand(){ mDPS = 8; } function offhand(){ oDPS = 4; } function Update(){ if(Input.GetKeyDown(KeyCode.R)){ mainhand(); Debug.Log("MainHand Equipped!"); } if(Input.GetKeyDown(KeyCode.T)){ offhand(); Debug.Log("OffHand Equipped!"); } enemy = GameObject.FindWithTag("enemy"); var enScript = enemy.GetComponent(Enemy); if(enScript.readyforattack){ if(Input.GetMouseButtonDown(0)){ damage(); } } } function damage(){ enemy = GameObject.FindWithTag("enemy"); var enScript = enemy.GetComponent(Enemy); var statScript = transform.GetComponent(Attributes); dmg = mDPS + oDPS + (statScript.STRENGTH/2); enScript.health -= dmg; statScript.recalculateStats(); Debug.Log(dmg); } Enemy.js var health : int = 20; var readyforattack : boolean = false; function Update(){ if(health <= 0){ Destroy(gameObject); } } function OnMouseOver(){ readyforattack = true; } function OnMouseExit(){ readyforattack = false; }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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