Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Cant seem to hurt the 2D enemy

$
0
0
I have tried various ways to inflict damage and nothing seems to work.... this is my latest attempt: using UnityEngine; using System.Collections; using System; public class FireBlast : MonoBehaviour { public float speed; private Player player; private int BaseLayer; public int damagePerShot = 20; public float timeBetweenBullets = 0.15f; public float range = 50f; float timer; Ray2D FirePoint; RaycastHit2D shootHit; int shootableMask; float effectsDisplayTime = 0.2f; void Start() { player = FindObjectOfType(); if (player.transform.localScale.x < 0){ speed = -speed; transform.localScale = new Vector3(-1f, 1f, 1f); } } void FixedUpdate() { GetComponent().velocity = new Vector2(speed, GetComponent().velocity.y); } void OnTriggerEnter2D(Collider2D other) { // Reset the timer. timer = 0f; // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. FirePoint.origin = transform.position; FirePoint.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics2D.Raycast(FirePoint.origin, shootHit.point, range, shootableMask, 10f)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.rigidbody.GetComponent(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } } } } I am trying to kill enemies with a basic health system.. Please help!

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>