ایده ساخت یک تایمر بمب در یونیتی
شنبه, ۱۳ شهریور ۱۳۹۵، ۰۸:۴۶ ق.ظ
gameover.blog.ir
به طوریکه وقتی شی ای با تگ پلیر به بمب نزدیک شد منفجر شود یا عمل خاصی انجام شود(که باید دستور لازم اضافه شود)
using UnityEngine; public class CannonBall : MonoBehaviour { public float waitTime = 1f; float timer; bool timerRunning; void Update () { if (timerRunning) { BombTimer(); } } void BombTimer() { timer += Time.deltaTime; if (timer > waitTime) { //Cannon ball bomb explodes timer = 0f; timerRunning = false; } } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { timerRunning = true; } } }
۹۵/۰۶/۱۳