Created
November 19, 2019 19:14
-
-
Save Drenerdo/cf05ae222dbd9e50fc0ef28f85064729 to your computer and use it in GitHub Desktop.
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; | |
public class CustomEnemyAI : MonoBehaviour | |
{ | |
public Transform target; | |
public float moveSpeed; | |
public float rotationSpeed; | |
public float sinkSpeed; | |
public float attackDistance = 1f; | |
public float radius = 3f; | |
public bool showEnemyDebug; | |
public EnemyShooting shootProjectile; | |
void Start() | |
{ | |
shootProjectile = GetComponentInChildren<EnemyShooting>(); | |
} | |
void Update() | |
{ | |
if (Vector3.Distance(target.position, transform.position) > attackDistance) | |
{ | |
Debug.Log("Holding fire!"); | |
} | |
else | |
{ | |
Debug.Log("Attacking!!!"); | |
// For now enemy will stop in the same position as the target gameobject | |
moveSpeed = 0; | |
rotationSpeed = 0; | |
//shootProjectile.Shoot(); | |
} | |
target = GameObject.FindGameObjectWithTag("Target").transform; | |
target.LookAt(target); | |
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position), rotationSpeed * Time.deltaTime); | |
transform.position += transform.forward * Time.deltaTime * moveSpeed; | |
transform.Translate(Vector3.down * sinkSpeed * Time.deltaTime); | |
} | |
void OnDrawGizmosSelected() | |
{ | |
Gizmos.color = Color.green; | |
Gizmos.DrawWireSphere(transform.position, radius); | |
} | |
void OnDrawDizmos() | |
{ | |
Gizmos.color = Color.clear; | |
} | |
public void Sink() | |
{ | |
moveSpeed = 0.5f; | |
sinkSpeed = 0.5f; | |
gameObject.GetComponent<Rigidbody>().isKinematic = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment