-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
308 additions
and
69 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,68 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class EnemyController : MonoBehaviour { | ||
|
||
public Transform player; | ||
|
||
public float speed = 1f; | ||
public float checkFrequency = 1f; | ||
|
||
public float timeToDie = 1f; | ||
private float timeDead = 0f; | ||
private bool dead = false; | ||
|
||
private float lastCheck = 0f; | ||
private Vector3 direction; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
GetComponent<Renderer>().material.SetFloat(Shader.PropertyToID("Vector1_30FACB43"), (timeToDie - timeDead) / timeToDie); | ||
Debug.Log(GetComponent<Renderer>().material.GetFloat(Shader.PropertyToID("Vector1_30FACB43")) ); | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class EnemyController : MonoBehaviour { | ||
|
||
public GameObject player; | ||
|
||
public float speed = 1f; | ||
public float checkFrequency = 1f; | ||
|
||
public float timeToDie = 1f; | ||
private float timeDead = 0f; | ||
private bool dead = false; | ||
|
||
private float lastCheck = 0f; | ||
private Vector3 direction; | ||
private Rigidbody rb; | ||
private EnemyProperties enemy; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
rb = GetComponent<Rigidbody>(); | ||
enemy = GetComponent<EnemyPropertyController>().properties; | ||
Debug.Log(GetComponent<Renderer>().material.GetFloat(Shader.PropertyToID("Vector1_30FACB43"))); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
|
||
if(dead) { | ||
|
||
timeDead += Time.deltaTime; | ||
|
||
GetComponent<Renderer>().material.SetFloat(Shader.PropertyToID("Vector1_30FACB43"), (timeToDie - timeDead) / timeToDie); | ||
|
||
if(timeToDie - timeDead <= 0) { | ||
Destroy(this.gameObject); | ||
} | ||
|
||
return; | ||
} | ||
|
||
lastCheck += Time.deltaTime; | ||
|
||
if(lastCheck >= checkFrequency) { | ||
lastCheck = 0; | ||
|
||
UpdateEnemyPath(); | ||
} | ||
|
||
transform.Translate(direction * speed * Time.deltaTime, Space.World); | ||
} | ||
|
||
void UpdateEnemyPath() { | ||
direction = (player.position - transform.position).normalized; | ||
} | ||
|
||
public void OnDeath() { | ||
dead = true; | ||
} | ||
} | ||
void Update () { | ||
|
||
if(dead) { | ||
|
||
timeDead += Time.deltaTime; | ||
|
||
GetComponent<Renderer>().material.SetFloat(Shader.PropertyToID("Vector1_30FACB43"), timeToDie - timeDead); | ||
|
||
return; | ||
} | ||
|
||
lastCheck += Time.deltaTime; | ||
|
||
if(lastCheck >= checkFrequency) { | ||
lastCheck = 0; | ||
|
||
UpdateEnemyPath(); | ||
} | ||
|
||
transform.Translate(direction * speed * Time.deltaTime, Space.World); | ||
} | ||
|
||
private void OnCollisionEnter(Collision collision) { | ||
if (collision.collider.CompareTag("Player")) { | ||
rb.AddForce((player.transform.position - transform.position).normalized, ForceMode.Impulse); | ||
player.GetComponent<PlayerControl>().AddDamage(enemy.attackDamage); | ||
} | ||
} | ||
|
||
void UpdateEnemyPath() { | ||
direction = (player.transform.position - transform.position).normalized; | ||
} | ||
|
||
public void OnDeath() { | ||
dead = true; | ||
|
||
Debug.Log("Dead"); | ||
} | ||
} |
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