Last active
April 17, 2019 21:55
-
-
Save webthingee/f2815649e85d3b7915ea7dabd4563f50 to your computer and use it in GitHub Desktop.
Quick List
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
Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, rangeRadius, masksToTarget); | |
if (hits.Length < 1) | |
{ | |
myTarget = null; | |
myTargetDirection = Vector2.down; | |
} | |
float closest = Mathf.Infinity; | |
foreach (Collider2D hit in hits) | |
{ | |
float distance = Vector2.Distance(transform.position, hit.transform.position); | |
if (distance < closest) | |
{ | |
closest = distance; | |
myTarget = hit.gameObject; | |
myTargetDirection = (hit.transform.position - transform.position).normalized; | |
} | |
} |
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
return Camera.main.ViewportToWorldPoint(new Vector2(Random.value, Random.value)); |
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
private void Awake() | |
{ | |
if (visualZone != null) return; | |
UnityEditor.EditorApplication.isPlaying = false; | |
Debug.LogError("Assign the " + visualZone.name + " in the inspector before resuming"); | |
} |
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
myTargetDirection = (hit.transform.position - transform.position).normalized; | |
transform.up = Vector3.Slerp(transform.up, myTargetDirection, Time.deltaTime * rotationSpeed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment