Created
July 19, 2020 15:19
-
-
Save naylinhtun1/2c8bb355e2df43060243a40afe0e73ba to your computer and use it in GitHub Desktop.
#enemy #health #Unity #3D #FPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Target : MonoBehaviour | |
{ | |
public float healt = 50f;//this is our enemy health | |
public Animator anim;//this is our enemy animator | |
bool die;//die animation will appear when enemy is shaw (bool means ture or false not truth or dare) | |
private void Start() | |
{ | |
anim = GetComponent<Animator>();//where do we get animator component? | |
} | |
public void Takedamage(float amout)//how do we take a damage when player shoot | |
{ | |
healt -= amout;//health will minus of amout what does it mean? it mean when player shoot enemy (health will -1 (50-1=49)but in shooting script player will take 10 so (50-10=40)) myan myan thay | |
if(healt<= 0f)//if health is less than 0 enemy will die(-1/0) | |
{ | |
Die();//how do we die? | |
} | |
} | |
void Die() | |
{ | |
anim.SetBool("isDie", true);//we make a animation call die with a bool of "isDie" and it true (appear) | |
Destroy(gameObject, 1.5f);//we don't want enemy shaw body so we destory it in 1.5sec | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment