32 lines
704 B
C#
32 lines
704 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
|
||
|
public class DeathWall : MonoBehaviour
|
||
|
{
|
||
|
public Transform player;
|
||
|
public float speed = 2f;
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
if (player != null)
|
||
|
{
|
||
|
Vector3 targetPosition = new Vector3(player.position.x, transform.position.y, transform.position.z);
|
||
|
transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnTriggerEnter2D(Collider2D other)
|
||
|
{
|
||
|
|
||
|
if (other.CompareTag("Player"))
|
||
|
{
|
||
|
SceneManager.LoadScene("GameOverScene");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|