Commit 378c1525 authored by wayland bang's avatar wayland bang
Browse files

fixed detection and some hitboxes (enemy)

parent b3f7268a
fileFormatVersion: 2
guid: 7580e7a14bdec4cf3a38f24b94dfae3f
guid: dafc79ccda6b647a085122f400c28480
folderAsset: yes
timeCreated: 1476045420
licenseType: Free
......
......@@ -20,7 +20,15 @@ public class enemyScript : MonoBehaviour {
protected SpriteRenderer spriteRend;
protected Rigidbody2D rb;
public bool playerInRange;
public LayerMask playerLayer;
public float sightRadius;
void Update(){
if (Time.time > this.nextFireTime_sec) {
this.isCanFireNow = true;
this.nextFireTime_sec = Time.time + this.rateOfFire_sec;
......@@ -51,9 +59,18 @@ public class enemyScript : MonoBehaviour {
}
void FixedUpdate(){
Vector2 facingdirection = player.position - transform.position;
Vector2 facingdirection = player.position - transform.position;
if (this.rb.velocity.magnitude < maxSpeed && Vector3.Distance(transform.position,player.position)> AttackRange) {
//if (this.rb.velocity.magnitude < maxSpeed && Vector3.Distance (transform.position, player.position) < AttackRange) {
// for
//}
playerInRange = Physics2D.OverlapCircle(transform.position, sightRadius, playerLayer);
//this.rb.velocity.magnitude < maxSpeed && Vector3.Distance(transform.position,player.position)> AttackRange
if (playerInRange) {
//Vector2 force = Vector2.MoveTowards (this.transform.position, player.position, speed);
this.rb.AddForce (facingdirection.normalized * speed);
}
......@@ -73,9 +90,9 @@ public class enemyScript : MonoBehaviour {
}
transform.position = new Vector3(transform.position.x, transform.position.y, 0);
}
// void OnCollisionEnter2D(Collision2D other){
// if (other.CompareTag ("Projectile")) {
// //get damage
......@@ -87,4 +104,11 @@ public class enemyScript : MonoBehaviour {
// Destroy(other.gameobject)
}
void OnDrawGizmosSelected() {
// Display the explosion radius when selected
Gizmos.DrawSphere (transform.position, sightRadius);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment