using System.Collections; using System.Collections.Generic; using UnityEngine; public class TriggerScript : MonoBehaviour { public GameObject m_player; public Transform safeBoden; public LogicScript logic; public Transform cam; public Transform bg; private MovementScript movementScript; private Transform player_transform; [field: SerializeField] public int direction; public MovementScript thisScript1; public MovementScript thisScript2; void Start() { m_player = GameObject.FindGameObjectWithTag("Player"); movementScript = GameObject.FindGameObjectWithTag("Level").GetComponent(); player_transform = GameObject.FindGameObjectWithTag("Player").GetComponent(); safeBoden = GameObject.Find("Safe_Boden").GetComponent(); logic = GameObject.FindGameObjectWithTag("Logic").GetComponent(); cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent(); bg = GameObject.FindGameObjectWithTag("Background").GetComponent(); thisScript1 = GameObject.Find("Trigger_01").GetComponent(); thisScript2 = GameObject.Find("Trigger_02").GetComponent(); if(gameObject.name == "Trigger_01"){ direction = 1; } else if(gameObject.name == "Trigger_02"){ direction = -1; } } void Update () { if(movementScript.direction==1){ thisScript1.direction = -1; thisScript2.direction = -1; } else if(movementScript.direction==-1){ thisScript1.direction = 1; thisScript2.direction = 1; } } private void OnTriggerEnter2D(Collider2D collider) { Debug.Log("Collision with " + collider.gameObject.name); } }