Untitled
unknown
plain_text
a year ago
761 B
14
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Damage : MonoBehaviour
{
[SerializeField] private float damageLevel = 1f;
[SerializeField] private Health playerHealth;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Player")
{
if (playerHealth == null)
{
playerHealth = collision.gameObject.GetComponent<Health>();
}
playerHealth.TakeDamage(damageLevel);
}
}
}
Editor is loading...
Leave a Comment