mirror of
https://github.com/frizbee19/FebGameJam.git
synced 2026-10-11 18:19:11 +00:00
did a minor tweak
This commit is contained in:
1 parent
8f2a693284
commit
11a2af2f5f
302 files changed
+1022
-167
No files matched your search
@@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
//to implement inheritance
|
||||
public abstract class Trigger : MonoBehaviour
|
||||
{
|
||||
//tags for the trigger
|
||||
public bool forceInteract;
|
||||
public bool repeatable;
|
||||
bool isActive;
|
||||
//only worry about this if it is not repeatable
|
||||
bool hasOccurred;
|
||||
public int value;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
hasOccurred = false;
|
||||
}
|
||||
|
||||
//checks if player is in range of the trigger
|
||||
private void OnTriggerStay2D(Collider2D other) {
|
||||
if(other.CompareTag("Player")) {
|
||||
Debug.Log("entered");
|
||||
isActive = true;
|
||||
}
|
||||
// else {
|
||||
|
||||
// isActive = false;
|
||||
// Debug.Log("exit");
|
||||
|
||||
// if(forceInteract && repeatable) {
|
||||
// hasOccurred = false;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other) {
|
||||
if(other.CompareTag("Player")) {
|
||||
isActive = false;
|
||||
Debug.Log("exit");
|
||||
}
|
||||
if(forceInteract && repeatable) {
|
||||
hasOccurred = false;
|
||||
}
|
||||
}
|
||||
// Update is called once per frame
|
||||
public void Update()
|
||||
{
|
||||
// Debug.Log("testr");
|
||||
//checks if conditions are right
|
||||
if(isActive && !hasOccurred)
|
||||
{
|
||||
//executes action upon entering
|
||||
if(forceInteract)
|
||||
{
|
||||
Action();
|
||||
hasOccurred = true;
|
||||
if(!repeatable) {
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
//only executes action if input is pressed
|
||||
else
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.E)) {
|
||||
Debug.Log("action");
|
||||
Action();
|
||||
if(!repeatable)
|
||||
{
|
||||
hasOccurred = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Action();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user