Files
FebGameJam/Assets/Jacob Folder/Ceiling_Trigger.cs
T
Unknown 023b003cbe Ceiling Trigger made easy as a prefab
Should work just fine, use the sliders to determine how far you want the char to go.
2022-02-25 22:52:58 -06:00

48 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ceiling_Trigger : MonoBehaviour
{
public GameObject cam;
public GameObject cat;
public BoxCollider2D box;
private int counter = 0;
[Range (1f,25f)]public float camOffset = 10f;
[Range (1f,15f)] public float catOffset = 5f;
[Range(5, 180)] public int countOffset = 10;
private Vector3 moveCam;
private Vector3 moveCat;
// Start is called before the first frame update
void Start()
{
moveCam = new Vector3(0, camOffset, 0);
moveCat = new Vector3(0, catOffset, 0);
}
// Update is called once per frame
void Update()
{
counter++;
}
void OnTriggerEnter2D(Collider2D col)
{
float ye = cat.transform.position.y;
float goaly = box.transform.localPosition.y;
if (ye < goaly && counter >= countOffset)
{
cam.transform.position += moveCam;
cat.transform.position += moveCat;
counter = 0;
}
else if (ye >= goaly && counter > countOffset)
{
cam.transform.position -= moveCam;
cat.transform.position -= moveCat;
counter = 0;
}
}
}