Can anyone change these to 2d Physics?

So, I wrote some scripts for my 2d game, but I made them use 3d physics, so now I can’t fix them. Help would greatly be appreaciated. The two scripts are to on collision make the player respawn

using UnityEngine;
using System.Collections;

public class MYCLASSNAME : MonoBehaviour {
Transform spawn;

void OnTriggerEnter ( Collider other ){ if (cother.tag == “Player”)
{ other.transform.position = spawn.position; }
}
}

And to make audio play on collision

Also, if someone could format them correctly, that would make my day :slight_smile:

This should fix it. (BTW: use code tags when you post code!)

using UnityEngine;
using System.Collections;

public class AudioTest : MonoBehaviour {
    public AudioClip myClip;
    public AudioSource audio;

    void Start()
    {
        audio.clip = myClip;
    }

    void OnTriggerEnter2D(Collider2D obj)
    {
        if (obj.tag == "Player")
        {
            audio.Play();
        }
        else
        {
            audio.Stop();
        }
    }
}
using UnityEngine;
using System.Collections;

public class MYCLASSNAME : MonoBehaviour
{
    Transform spawn;    // you need to set this to something!!!

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            other.transform.position = spawn.position;
        }
    }
}
1 Like