Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- var Gun: GameObject;
- var Player: Transform;
- var Enemy: Transform;
- var EnemyHealth: GameObject;
- var EnemyHealthINT: int = 100;
- var hit: RaycastHit;
- var shootingDis: float = 15;
- var AmmoText: GameObject;
- var Ammo: int = 50;
- function Start () {
- EnemyHealth.GetComponent(TextMesh).text = "100";
- AmmoText.GetComponent(UI.Text).text = "50";
- shootingDis = 15;
- }
- function Update () {
- Enemy.transform.rotation = Quaternion.LookRotation(Enemy.position - Player.position);
- if (Physics.Raycast(transform.position, transform.forward, hit, shootingDis)) {
- if(hit.transform.tag == "Enemy") {
- if(Ammo >= 1) {
- if(Input.GetMouseButtonDown(0)) {
- EnemyHealthINT -= 10;
- EnemyHealth.GetComponent(TextMesh).text = EnemyHealthINT.ToString();
- }
- }
- }
- }
- if(Input.GetMouseButtonDown(0)) {
- AmmoText.GetComponent(UI.Text).text = Ammo.ToString();
- Ammo -= 1;
- }
- if(Input.GetKeyDown(KeyCode.R)) {
- Ammo = 50;
- AmmoText.GetComponent(UI.Text).text = Ammo.ToString();
- }
- if(Ammo <= 0) {
- Ammo = 0;
- }
- if (EnemyHealthINT == 0) {
- Destroy(Enemy.gameObject);
- }
- }
Add Comment
Please, Sign In to add comment