public AudioClip attack; // Audio to play when the bot attack. public void Attack(float attackRate, RaycastHit hit) // attackSpeed ? { if (hit.rigidbody) { BotHealth target = hit.rigidbody.GetComponent <BotHealth>(); // Debug.Log("BotAttack : " + Time.time + " | " + nextAttackTime + " | " + target); // Find the BotHealth script associated with the rigidbody. if (target) { if (Time.time > nextAttackTime && target.isActiveAndEnabled) { nextAttackTime = Time.time + attackRate; // Set the fired flag so only Fire is only called once. attacked = true; Audio(); if (target.getHealth() <= 0) { return; } target.TakeDamage(damage); } } } }
private void OnTriggerEnter(Collider other) { // Find the BotHealth script associated with the rigidbody. BotHealth targetHealth = other.GetComponent <BotHealth>(); // If there is no BotHealth script attached to the gameobject if (targetHealth) { targetHealth.TakeDamage(5); // Deal this damage to the AI. } /* * // Unparent the particles from the bullet. * explosionParticles.transform.parent = null; * * // Play the particle system. * explosionParticles.Play(); * * // Play the explosion sound effect. * explosionAudio.Play(); * * // Once the particles have finished, destroy the gameobject they are on. * ParticleSystem.MainModule mainModule = explosionParticles.main; * Destroy(explosionParticles.gameObject, mainModule.duration); */ // Destroy the shell. Destroy(gameObject); }
void Start() { botAttack = GetComponent <BotAttack>(); botHealth = GetComponent <BotHealth>(); botMovement = GetComponent <BotMovement>(); botMovement.navMeshAgent.speed = aiParameters.moveSpeed; // If "Failed to create agent because it is not close enough to the NavMesh" appears // that's because the object linked with nma is too far from the floor for example }