| 123456789101112131415161718192021 |
- using UnityEngine;
- public class Bullet : MonoBehaviour
- {
- public float speed = 20f;
- void Update()
- {
- transform.Translate(Vector3.forward * speed * Time.deltaTime);
- Destroy(gameObject, 3f);// Destroy bullet after 3s
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Target"))
- {
- other.GetComponent<Target>().TakeDamage();
- Destroy(gameObject);
- }
- }
- }
|