Files
GameDevTVObstacleDodge/Assets/Scripts/ObjectHit.cs

16 lines
453 B
C#
Raw Normal View History

2026-01-08 16:50:20 +00:00
using UnityEngine;
public class ObjectHit : MonoBehaviour
{
2026-01-09 10:41:51 +00:00
[SerializeField] int damageAmount = 10;
2026-01-08 16:50:20 +00:00
private void OnCollisionEnter(Collision other)
{
2026-01-09 10:41:51 +00:00
if (other.gameObject.tag == "Player" && gameObject.tag != "Hit")
2026-01-08 16:50:20 +00:00
{
GetComponent<MeshRenderer>().material.color = Color.black;
gameObject.tag = "Hit";
2026-01-09 10:41:51 +00:00
other.gameObject.GetComponent<PlayerStats>().TakeDamage(damageAmount);
2026-01-08 16:50:20 +00:00
}
}
}