Script Destroy GameObject With Health
4 posters
Page 1 of 1
Script Destroy GameObject With Health
Sedikit Script Destroy Object Bagi Yang Mau Buat Game (Beserta Health)
Thanks To : Ilham Hasymi Effendi & BurgZergArcade
Nih Scriptnya(Unity 3d) (C# Script) :
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public int health;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI() {
GUI.Box(new Rect(10, 40, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
if(curHealth <= 0){
Destroy(gameObject);
}
}
}
Semoga Membantu Ya Scriptnya, Hehehehehe
Thanks To : Ilham Hasymi Effendi & BurgZergArcade
Nih Scriptnya(Unity 3d) (C# Script) :
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public int health;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI() {
GUI.Box(new Rect(10, 40, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
if(curHealth <= 0){
Destroy(gameObject);
}
}
}
Semoga Membantu Ya Scriptnya, Hehehehehe
KzRaItoN- Unity3D Newbie
- Posts : 19
Points : 31
Reputation : 0
Join date : 2012-09-05
Re: Script Destroy GameObject With Health
wah...setelah sekian lama ane nongkron di sini.,... akhirnya ada mastah yang posting....
trutions- Unity3D Newbie
- Posts : 6
Points : 11
Reputation : 3
Join date : 2012-09-21
Re: Script Destroy GameObject With Health
hehehehehe, Iya Nih, Thanks ya dah mampirtrutions wrote:wah...setelah sekian lama ane nongkron di sini.,... akhirnya ada mastah yang posting....
KzRaItoN- Unity3D Newbie
- Posts : 19
Points : 31
Reputation : 0
Join date : 2012-09-05
Re: Script Destroy GameObject With Health
setidaknya setiap baris yg diketik juga dipahami, hayo semangat
Re: Script Destroy GameObject With Health
Biar kata postingan udah lewat 2 tahun juga mesti tetap di apresiasi. Good job, master!
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Thu Mar 23, 2017 10:21 am by kamil
» [ASK HELP] Slide informasi di augmented reality
Tue Jan 03, 2017 8:58 pm by Briyan_ap
» ASK cara klik dan memunculkan informasi
Tue Jan 03, 2017 8:54 pm by Briyan_ap
» [Ask] mengubah game PC menjadi game Android
Tue Jan 03, 2017 10:57 am by NiethaChan
» Virtualisasi suatu Gedung mengunakan unity3D + google seketchUP
Sat Dec 31, 2016 1:06 am by zeepank
» Minta Tolong, slideshow ngga muncul saat object di klik
Tue Dec 27, 2016 12:53 pm by Briyan_ap
» tolong dong lagi bikin button rotate tp button ga keluar
Wed Dec 21, 2016 1:15 pm by Lita Misae
» algoritma Minimax/negascout buat checkers
Wed Nov 30, 2016 1:51 am by ardiansa
» screenshot
Wed Nov 16, 2016 10:15 pm by azhari