Ceiling Trigger made easy as a prefab

Should work just fine, use the sliders to determine how far you want the char to go.
This commit is contained in:
Unknown committed 2022-02-25 22:52:58 -06:00
1 parent 0d8b440f57
commit 023b003cbe
12 files changed
+566 -336

No files matched your search

@@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2424016421282532468
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2424016421282532469}
- component: {fileID: 2424016421282532427}
- component: {fileID: 2424016421282532426}
m_Layer: 8
m_Name: Ceiling Trigger Prefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2424016421282532469
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2424016421282532468}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 21.5, y: 5.5, z: -1.3}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &2424016421282532427
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2424016421282532468}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 20, y: 2}
m_EdgeRadius: 0
--- !u!114 &2424016421282532426
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2424016421282532468}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5cf4f43ae0936c443a05276d3fd59404, type: 3}
m_Name:
m_EditorClassIdentifier:
cam: {fileID: 0}
cat: {fileID: 0}
box: {fileID: 2424016421282532427}
camOffset: 10
catOffset: 5
countOffset: 10
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 90ba0415d16f59348b613f49f06bc4b1
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+14 -15
View File
@@ -4,18 +4,21 @@ using UnityEngine;
public class Ceiling_Trigger : MonoBehaviour
{
bool entered = false;
public GameObject cam;
public GameObject cat;
public BoxCollider2D box;
private int counter = 0;
private Vector3 moveCam = new Vector3(0, 10, 0);
private Vector3 moveCat = new Vector3(0, 5, 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
@@ -25,23 +28,19 @@ public class Ceiling_Trigger : MonoBehaviour
}
void OnTriggerEnter2D(Collider2D col)
{
if (!entered && counter >= 6)
float ye = cat.transform.position.y;
float goaly = box.transform.localPosition.y;
if (ye < goaly && counter >= countOffset)
{
entered = true;
//Debug.Log("Move Cam Right");
cam.transform.position += moveCam;
cat.transform.position += moveCat;
Debug.Log(counter);
counter = 0;
}
else if (counter >= 6 && entered)
else if (ye >= goaly && counter > countOffset)
{
//Debug.Log("Moved cam left");
Debug.Log(counter);
cam.transform.position -= moveCam;
//cat.transform.position -= moveCat;
entered = false;
cat.transform.position -= moveCat;
counter = 0;
}
}
@@ -0,0 +1,182 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &776050268538294905
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1930438974301739882}
- component: {fileID: 6013133612863668949}
m_Layer: 8
m_Name: Hitbox
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1930438974301739882
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 776050268538294905}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.191, y: -0.063, z: 0}
m_LocalScale: {x: 0.16666667, y: 0.16666667, z: 1}
m_Children: []
m_Father: {fileID: 3103723802129481039}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &6013133612863668949
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 776050268538294905}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 2.79, y: 6.9}
m_EdgeRadius: 0
--- !u!1 &3103723802129481037
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3103723802129481039}
- component: {fileID: 3103723802129481036}
- component: {fileID: 3103723802129481033}
- component: {fileID: 3103723802129481074}
m_Layer: 8
m_Name: Spoopy Ghoste (Jumpscare Warning)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3103723802129481039
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3103723802129481037}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 20, y: 3.51, z: 0}
m_LocalScale: {x: 2, y: 2, z: 1}
m_Children:
- {fileID: 1930438974301739882}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &3103723802129481036
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3103723802129481037}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 1027733709
m_SortingLayer: 2
m_SortingOrder: 0
m_Sprite: {fileID: -5029764186598712489, guid: 1a0db7ae73c9e43ac856b25d6ad47dbc, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 0.16, y: 0.16}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!50 &3103723802129481033
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3103723802129481037}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 0.0001
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!114 &3103723802129481074
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3103723802129481037}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f19ade9cdbc8e314195b298d78e2f5c7, type: 3}
m_Name:
m_EditorClassIdentifier:
boxCollider: {fileID: 6013133612863668949}
swimSpeed: 5
cat: {fileID: 0}
ball: 0
mvt: {fileID: 0}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f0e8347bd54ddbf468a7b473d6776446
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UpdatedCeilingTrigger : MonoBehaviour
{
public RaycastHit2D hit;
public Ray ray;
private LayerMask layerMask;
private float angleStep = 8;
public Transform target;
[Range(1f, 10f)] public float rayLength = 10f;
public BoxCollider2D box;
public GameObject camMove;
public GameObject catMove;
private int counter = 0;
// Start is called before the first frame update
void Start()
{
layerMask = LayerMask.GetMask("Player");
}
// Update is called once per frame
void Update()
{
for (int i = 1; i <= angleStep; i++)
{
var rayAngle = Quaternion.AngleAxis((360f / angleStep) * i, target.forward) * Vector3.left;
hit = Physics2D.Raycast(target.position, rayAngle, rayLength, layerMask);
float xe = Mathf.Abs(hit.point.x - target.localPosition.x);
float ye = Mathf.Abs(hit.point.y - target.localPosition.y);
float goalx = Mathf.Abs(target.position.x * box.size.x);
float goaly = Mathf.Abs(target.position.y * box.size.y);
if (hit && counter >= 150)
{
if (ye >=1)
{
Debug.Log("Counter Up " + counter);
Debug.Log("YE " + ye);
Debug.Log("Goaly " + goaly);
Debug.Log(target.position.y * box.size.y);
camMove.transform.position = new Vector3(camMove.transform.position.x + 22f, camMove.transform.position.y, -1.3f);
catMove.transform.position = new Vector3(catMove.transform.position.x + 10f, catMove.transform.position.y + 1f, 0);
xe = 0;
ye = 0;
goalx = 0;
goaly = 0;
counter = 0;
}
else
{
Debug.Log("Counter Down " + counter);
Debug.Log("YE " + ye);
Debug.Log("Goaly " + goaly);
camMove.transform.position = new Vector3(camMove.transform.position.x - 22f, catMove.transform.position.y + 1.0f, -1.3f);
catMove.transform.position = new Vector3(catMove.transform.position.x - 10f, catMove.transform.position.y, 0);
counter = 0;
xe = 0;
ye = 0;
goalx = 0;
goaly = 0;
}
}
counter++;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c52b4040d972fe74bb3489c91de44fef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: