Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Last active May 27, 2017 18:03
Show Gist options
  • Save unity3dcollege/f41c8bf1fcdc580f3d2075b74d955715 to your computer and use it in GitHub Desktop.
Save unity3dcollege/f41c8bf1fcdc580f3d2075b74d955715 to your computer and use it in GitHub Desktop.
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