Last active
May 27, 2017 18:03
-
-
Save unity3dcollege/f41c8bf1fcdc580f3d2075b74d955715 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnityEditor; | |
using UnityEngine; | |
[CustomEditor(typeof(EnemySpawner))] | |
public class EnemySpawnerEditor : Editor | |
{ | |
private EnemySpawner _enemySpawner; | |
public override void OnInspectorGUI() | |
{ | |
_enemySpawner = (EnemySpawner)target; | |
base.OnInspectorGUI(); | |
EditorGUILayout.MinMaxSlider( | |
new GUIContent("Movement Speed"), | |
ref _enemySpawner.MinMovementSpeed, | |
ref _enemySpawner.MaxMovementSpeed, | |
0f, | |
100f); | |
if (GUILayout.Button("Add Random Waypoint")) | |
AddRandomWaypoint(); | |
if (GUILayout.Button("Add Static Route Waypoint")) | |
AddStaticRouteWaypoint(); | |
RoundSpeedValues(); | |
DisableRendererAndCollider(); | |
StickSpawnerToGround(); | |
// Set the spawners name in the Hierarchy | |
_enemySpawner.gameObject.name = _enemySpawner.ToString(); | |
} | |
private void StickSpawnerToGround() | |
{ | |
_enemySpawner.transform.rotation = Quaternion.identity; | |
RaycastHit hitInfo; | |
int layerMask = LayerMask.GetMask("EnvironmentAndGround"); | |
if (Physics.Raycast(_enemySpawner.transform.position, Vector3.down, out hitInfo, 2f, layerMask)) | |
{ | |
_enemySpawner.transform.position = new Vector3(_enemySpawner.transform.position.x, hitInfo.point.y, _enemySpawner.transform.position.z); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment