So I am currently developing a small 2D platformer! However I am having some issues with my Checkpoint system, I am still very new to C# and Unity so don't be to harsh on me!
Anyways, what is ment to happen is, Player touches checkpoint (a blue gem) The blue gem dissapears and makes a noise and then that is where he will spawn!
The issue is, the checkpoints work fine, but if I add the whole "Make a noise and then dissapear" It will make the noise and dissapear but not set his checkpoint anymore! >_<
Here is the code, but I would really prefer someone helping me over teamviewer or something, so I can learn how to fix the issue!
using UnityEngine;
using System.Collections;
public class CheckPoint : MonoBehaviour {
public static bool checkpointEnabled = false;
public static GameObject initSpawn;
public static GameObject checkpoint;
public static GameObject respawn;
public AudioClip[] audioClip;
void Start ()
{
initSpawn = GameObject.FindWithTag("Spawn");
checkpoint = GameObject.FindWithTag("CheckPoint");
respawn = initSpawn;
}
void Update ()
{
if (checkpointEnabled)
{
respawn = checkpoint;
}
}
//Set the checkpoint!
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
checkpointEnabled = true;
Debug.Log ("CheckPoint!");
}
}
//Play sound and delete object
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Player")
{
transform.Translate(Vector3.up * 15f, Space.World);
PlaySound (0);
Destroy(this.gameObject, 1f);
}
}
void PlaySound(int clip)
{
audio.clip = audioClip [clip];
audio.Play ();
}
}