Hey guys I have a simple 2D game where a character goes to the other side, when he hits the other side he is supposed to go the other way till he hits the other side and so on. And on the top is spike and when he hits them he is supposed to re-spawn. Both the spikes and the side walls are triggers with different tags but i don’t know how to find each of them in the script I tried but it came up with errors.
Here is the script.
using UnityEngine;
using System.Collections;
public class TriggerDeath : MonoBehaviour
{
public bool Switch = true;
void OnTriggerEnter2D ()
{
if(gameObject.tag == "Respawn")
{
Application.LoadLevel("Start");
Destroy(gameObject);
}
if(gameObject.tag == "Side")
{
if(Switch == true)
Switch = false;
if(Switch == false)
Switch = true;
}
}
void OnCollisionEnter2D ()
{
}
void Update ()
{
if(Switch == true)
rigidbody2D.AddForce(-Vector2.right * 1 * Time.deltaTime);
if(Switch == false)
rigidbody2D.AddForce(Vector2.right * 1 * Time.deltaTime);
}
}
Any help would be appreciated
Thx