// Update is called once per frame void Update() { time += Time.deltaTime; if (!startedAttack) { startedAttack = true; pmc.ForceMovement(null, upwardAttackSpeed); state.moveState = state.moveState.Remove(PlayerState.Movement.Falling); state.moveState = state.moveState.Include(PlayerState.Movement.Jumping); // TODO: Gravity mod? Increase speed and gravity? (So faster jump but slows down quickly?) } if (hitbox != null && !hit) { hitbox.Hit(gameObject); hitbox.emc.ForceMovement(null, upwardHitSpeed); hitbox = null; hit = true; } // Does this attack need a lifetime? /*if (time >= lifetime) { * Destroy(gameObject, 0f); * }*/ }
protected override void Fire() { //if the next shot is available and the gun is not overheated if (nextFire < Time.time && !overheated) { Quaternion rot = Quaternion.Euler(transform.eulerAngles.z, transform.eulerAngles.y - 90, 0); GameObject flash = Instantiate(muzzleFlash, fireLoc.position, rot); flash.transform.parent = gameObject.transform; //recoil stuff, commented out is another way to do it transform.position += new Vector3(0, Random.Range(upRecoil / 2, upRecoil), 0); //transform.position += Vector3.up * Random.Range(upRecoil / 2, upRecoil); transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(0, 0, Random.Range(-upRecoilRotation, -upRecoilRotation / 3))); //heat management nextFire = Time.time + fireRate; heat += heatPerShot; if (heat > maxHeat) { overheated = true; } //creates a bitmask for the enemyHibox layer int layerMask = 1 << 11; RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range, layerMask, QueryTriggerInteraction.Collide)) { EnemyHitbox enemyHitbox = hit.collider.transform.GetComponent <EnemyHitbox>(); if (enemyHitbox != null) { enemyHitbox.TakeDamageHandler(damage); } } } }
void OnTriggerExit(Collider other) { if (other.tag == "Enemy") { EnemyHitbox hitbox = other.transform.parent.gameObject.GetComponent <EnemyHitbox>(); hitbox.setPlayerWithinRange(false); } }
void OnTriggerStay(Collider other) { if (other.tag == "Enemy") { EnemyHitbox hitbox = other.transform.parent.gameObject.GetComponent <EnemyHitbox>(); hitbox.setPlayerWithinRange(true); hitbox.checkIfObstaclesAhead(transform.position); } }
/// <summary> /// Sent each frame where another object is within a trigger collider /// attached to this object (2D physics only). /// </summary> /// <param name="other">The other Collider2D involved in this collision.</param> void OnTriggerStay2D(Collider2D other) { if (other.gameObject.GetComponent <EnemyHitbox>()) { // Get enemy hitbox hit hitbox = other.gameObject.GetComponent <EnemyHitbox>(); } else if (other.gameObject.layer == LayerMask.NameToLayer("NormalCollisions")) { // Destroy if colliding with wall Destroy(gameObject, 0f); } }
// Update is called once per frame void Update() { time += Time.deltaTime; if (hitbox != null && !hit) { hitbox.Hit(gameObject); hitbox = null; hit = true; } if (time >= lifetime) { Destroy(gameObject, 0f); } }
private void OnTriggerEnter2D(Collider2D other) { EnemyHitbox enemyHitbox = other.GetComponent <EnemyHitbox>(); if (enemyHitbox != null) { AudioSource.PlayClipAtPoint(ChingSfx, transform.position, GameManager.Instance.Volume); } EnemyHurtbox enemyHurtbox = other.GetComponent <EnemyHurtbox>(); if (enemyHurtbox != null) { enemyHurtbox.TakeDamage(2f); } }
protected virtual void Awake() { animator = GetComponentInChildren <Animator>(); navMeshAgent = GetComponent <NavMeshAgent>(); rigidbody = GetComponent <Rigidbody>(); collider = GetComponent <Collider>(); damageable = new Damageable(maxHealth); damageable.AddDeathEffect(OnDeath); hitbox = GetComponentInChildren <EnemyHitbox>(); StartCoroutine(AttackRoutine()); StartCoroutine(SlowRoutine()); //StartCoroutine(ShelterUnderEnemyMageRoutine()); if (!todosAreLogged) { todosAreLogged = true; Debug.LogWarning("TODO: Enemy.ShelterUnderEnemyMageRoutine() is really hacky. Consider refactoring."); } }
private void OnTriggerEnter2D(Collider2D other) { EnemyHitbox enemyHitbox = other.GetComponent <EnemyHitbox>(); if (enemyHitbox != null) { Destroy(gameObject); return; } EnemyHurtbox enemyHurtbox = other.GetComponent <EnemyHurtbox>(); if (enemyHurtbox != null) { enemyHurtbox.TakeDamage(0.75f); Hit(); } else if (other.gameObject.layer == LayerMask.NameToLayer("Ground")) { Hit(); } }