void OnTriggerStay2D(Collider2D other) { if (other.gameObject.layer == LayerMask.NameToLayer("shootable")) { myPC.removeForce(); Instantiate(explosionEffect, transform.position, transform.rotation); Destroy(gameObject); //enemy health definition if (other.tag == "enemy") { enemyHealthController hurtEnemy = other.gameObject.GetComponent <enemyHealthController>(); hurtEnemy.addDamage(weaponDamage); } } }
// Use this for initialization void Start() { healthInvenurable = GetComponentInParent <enemyHealthController> (); zombieRB = GetComponentInParent <Rigidbody> (); zombieAnimator = GetComponentInParent <Animator> (); zombieSoundAudioSource = GetComponentInParent <AudioSource> (); detected = false; if (Random.Range(1, 2) == 1) { facingRight = true; turnAround(); } else { facingRight = false; } }
// Update is called once per frame void Update() { Vector3 mouseRay = new Vector3(Input.mousePosition.x, 2f, 0f); RaycastHit [] hits; Ray ray = Camera.main.ScreenPointToRay(mouseRay); //Vector3 rot; ray.origin = transform.position; ray.direction = mouseRay; int face = 1; if (mouseRay.x > player.transform.position.x && orientation.getOrientation() == -1) { gunLine.SetPosition(0, ray.origin + ray.direction * -range); face = -1; } else if (mouseRay.x > player.transform.position.x && orientation.getOrientation() == 1) { gunLine.SetPosition(0, ray.origin + ray.direction * range); face = 1; } hits = Physics.RaycastAll(ray.origin, ray.direction * face, range); for (int i = 0; i < hits.Length; i++) { if (hits[i].collider.tag == "Enemy") { Debug.Log("shoot it"); enemyHealthController enemyHealth = hits[i].collider.GetComponent <enemyHealthController> (); Debug.Log("hit enemy"); enemyHealth.enemyDeath(); } } }
// Update is called once per frame void Update() { Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z); shootRay = Camera.main.ScreenPointToRay(mousePos); if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { Debug.Log("hit something"); if (shootHit.collider.tag == "Enemy") { enemyHealthController enemyHealth = shootHit.collider.GetComponent <enemyHealthController> (); if (enemyHealth != null) { Debug.Log("hit enemy"); enemyHealth.enemeyGetDamage(damage); } } } }
void Start() { enemyHealth = GetComponentInParent <enemyHealthController> (); }