Skip to content

Instantly share code, notes, and snippets.

@CSaratakij
Created September 26, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CSaratakij/493053ad91a8543239406c2d347edd8d to your computer and use it in GitHub Desktop.
Save CSaratakij/493053ad91a8543239406c2d347edd8d to your computer and use it in GitHub Desktop.
Custom Collision
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class CustomCollision : MonoBehaviour
{
/*
public Vector3 offset;
public Vector2 size;
public LayerMask checkLayer;
*/
[SerializeField]
Vector3 offset;
[SerializeField]
Vector2 size;
[SerializeField]
public LayerMask checkLayer;
bool isFoundEnemy = false;
Collider2D target = null;
#if UNITY_EDITOR
void OnDrawGizmosSelected() {
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(transform.position + offset, size);
Handles.Label(transform.position, "Trigger Area");
}
#endif
void Update()
{
if (Input.GetKeyDown(KeyCode.G) && isFoundEnemy) {
//Attack...
}
}
void FixedUpdate()
{
target = Physics2D.OverlapBox(
transform.position + offset,
size,
0.0f,
checkLayer
);
isFoundEnemy = (target != null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment