Created
September 26, 2018 14:49
-
-
Save CSaratakij/493053ad91a8543239406c2d347edd8d to your computer and use it in GitHub Desktop.
Custom Collision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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