37 lines
834 B
C#
Raw Permalink Normal View History

2023-05-12 15:25:59 +02:00
using UnityEngine;
2023-06-25 11:21:42 +02:00
using System;
2023-05-12 15:25:59 +02:00
public class respawn : MonoBehaviour
{
private GameObject player;
[SerializeField] private Transform respawnPoint;
2023-06-25 11:21:42 +02:00
private AudioSource audioSource; // Reference to the AudioSource component
public AudioClip hurtSound; // The sound clip to be played
2023-05-12 15:25:59 +02:00
void Start()
{
player = GameObject.Find("Frank");
2023-06-25 11:21:42 +02:00
audioSource = GetComponent<AudioSource>();
2023-05-12 15:25:59 +02:00
}
void Update()
{
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Player"))
{
2023-06-25 11:21:42 +02:00
try{
audioSource.PlayOneShot(hurtSound);}
catch(Exception e){
;
}
2023-05-12 15:25:59 +02:00
player.transform.position = respawnPoint.position;
Debug.Log("Respawn: Move");
}
}
}