private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Enemy") { Debug.Log("triggered"); enemy.damage(); } if (collision.gameObject.tag == "Boss") { Debug.Log("boss hit"); boss.Damage(); } Destroy(gameObject); }
/* public void displayBullet() * { * int currentbullet = weapon.GetBulletNum(); * bulletText.text = currentbullet.ToString(); * Debug.Log("", bulletText); * * }*/ private void shoot() { if (weapon.GetBulletNum() > 0) { weapon.costBullet(); RaycastHit hit; if (Physics.Raycast(FPS.transform.position, FPS.transform.forward, out hit, range)) { HitEffect(hit); Debug.Log(" " + hit.transform.name); enemy target = hit.transform.GetComponent <enemy>(); target.damage(damage); } else { return; } } }
} // FixedUpdate void LaunchAttack(Collider objCollider) { float bufferTime = .3f; float timeSinceAttack = Time.realtimeSinceStartup - lastAttacked; Debug.Log(timeSinceAttack); if (attackState == 1) { float animationTime = .06f / .11f; if (timeSinceAttack < animationTime - bufferTime) { } else if (timeSinceAttack > animationTime + bufferTime) { attackState = 1; } } if (attackState == 2) { float animationTime = .06f / .07f; if (timeSinceAttack < animationTime - bufferTime) { } else if (timeSinceAttack > animationTime + bufferTime) { attackState = 1; } } if (attackState == 3) { float animationTime = .06f / .22f; if (timeSinceAttack < animationTime - bufferTime) { } else if (timeSinceAttack > animationTime + bufferTime) { attackState = 1; } } objCollider = attackHitboxes[0]; attack.Play(); animator.Play("PlayerAttack" + attackState); attackState += 1; lastAttacked = Time.realtimeSinceStartup; if (attackState > 3) { attackState = 1; } if (attackState == 3) { objCollider = attackHitboxes[1]; } // maybe make it so cooldown only animation if (attackTimer <= 0) { Collider[] enemyColliderInfo = Physics.OverlapBox(objCollider.bounds.center, objCollider.bounds.extents, objCollider.transform.rotation, LayerMask.GetMask("Enemy")); if (enemyColliderInfo.Length != 0) { for (int e = 0; e < enemyColliderInfo.Length; e++) { enemy Enemy = enemyColliderInfo[e].gameObject.GetComponent <enemy>(); if (Enemy != null) { Enemy.damage(1, -transform.localScale.x); } } attackTimer = attackCooldown; } else if (repairTimer <= 0) { Collider[] car = Physics.OverlapBox(objCollider.bounds.center, objCollider.bounds.extents, objCollider.transform.rotation, LayerMask.GetMask("car")); if (car.Length != 0) { Debug.Log("UICarHealth?"); carController thecar = car[0].gameObject.GetComponent <carController>(); thecar.ChangeHealth(1); Debug.Log(thecar.currentHealth); repairTimer = repairCooldown; } } } } // Launch Attack