void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; gunParticles.Stop(); gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { CompleteProject.EnemyHealth enemyHealth = shootHit.collider.GetComponent <CompleteProject.EnemyHealth> (); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } currentAmmo--; ammoText.text = "Ammo : " + currentAmmo.ToString(); }
void Shoot() { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); if (!currentMag.CanFeed()) { if (gunAudio.clip != dryFire) { gunAudio.clip = dryFire; } return; } // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void OnTriggerEnter(Collider other) { // If the entering collider is the player... if (other.gameObject == enemy) { // ... the player is in range. //playerInRange = true; enemyHealth.TakeDamage(attackDamage); } }
void beat() { timer = 0f; Collider[] enemys = Physics.OverlapSphere(player.transform.position, 3, shootableMask); for (int i = 0; i < enemys.Length; i++) { EnemyHealth enemyHealth = enemys[i].GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(200, enemyHealth.transform.position); } } }
void Shoot() { // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = boardHead.position; shootRay.direction = boardHead.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { gazePoint.position = shootHit.point; float Cachescale = 0.015f * (shootHit.point - boardHead.position).magnitude; gazePoint.localScale = new Vector3(Cachescale, Cachescale, Cachescale); EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } else { return; } // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.SetPosition(0, transform.position); gunLine.SetPosition(1, shootHit.point); gunLine.enabled = true; } else { gazePoint.localScale = Vector3.zero; } }
void OnTriggerEnter(Collider other) { if (other.tag == "Wall") { Destroy(gameObject); } else if (other.tag == "Enemy") { EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(Gun.damagePerShot, transform.position); Destroy(gameObject); } } }
public void Bomb() { Collider[] cols = Physics.OverlapSphere(transform.position, 6f); for (int i = 0; i < cols.Length; i++) { EnemyHealth enemyHealth = cols[i].GetComponent <EnemyHealth>(); if (enemyHealth) { enemyHealth.TakeDamage(enemyHealth.startingHealth, enemyHealth.transform.position); } } explosionEffect.SetActive(false); explosionEffect.SetActive(true); }
void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; faceLight.enabled = true; gunParticles.Stop(); gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { if (shootHit.collider.gameObject.CompareTag("Finish")) { Debug.Log("entro"); EnemyHealth resistencia = shootHit.collider.gameObject.GetComponent <EnemyHealth>(); if (resistencia != null) { resistencia.RegistrarImpacto(shootHit.point); gunLine.SetPosition(1, shootHit.point); } else { Destroy(shootHit.collider.gameObject, 1f); } } EnemyHealth enemyHealth = shootHit.collider.gameObject.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void Shoot() { Ray ray = Camera.main.ScreenPointToRay(new Vector3(w, h)); // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(ray, out shootHit)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... }
public void Shoot() { timer = 0f; //Play audio gunAudio.Play(); //enable Light gunLight.enabled = true; //Play gun particle gunParticles.Stop(); gunParticles.Play(); //enable Line renderer dan set first position gunLine.enabled = true; gunLine.SetPosition(0, transform.position); //Set posisi ray shoot dan direction shootRay.origin = transform.position; shootRay.direction = transform.forward; //Lakukan raycast jika mendeteksi id nemy hit apapun if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { //Lakukan raycast hit hace component Enemyhealth EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { //Lakukan Take Damage enemyHealth.TakeDamage(damagePerShot, shootHit.point); } //Set line end position ke hit position gunLine.SetPosition(1, shootHit.point); } else { //set line end position ke range freom barrel gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; gunParticles.Stop(); gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; // Bit shift the index of the layer (8) to get a bit mask int layerMask = 1 << 8; // This would cast rays only against colliders in layer 8. // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask. layerMask = ~layerMask; if (Physics.Raycast(shootRay, out shootHit, range, layerMask)) { CompleteProject.EnemyHealth enemyHealth = shootHit.collider.GetComponent <CompleteProject.EnemyHealth> (); ShatterOnCollision shatter = shootHit.collider.GetComponent <ShatterOnCollision>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } else if (shatter != null) { shatter.Action(); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, this.transform.position); } } var hitParticles = Instantiate(DataManager.Ins.hitParticles, transform.position, other.transform.rotation); hitParticles.Play(); Destroy(hitParticles, 2f); Destroy(this.gameObject); }
public void AirstrikeDamage(Vector3 detonationPoint) { // Dispatch event to flash EventManager.Instance.SendEvent("OnAirstrikeCollide"); // Get colliders in overlap sphere. Collider[] hitColliders = Physics.OverlapSphere(detonationPoint, blastRadius, shootableMask); // Iterate through colliders foreach (Collider hitCollider in hitColliders) { // get enemy health component. CompleteProject.EnemyHealth enemyHealth = hitCollider.gameObject.GetComponentInChildren <CompleteProject.EnemyHealth>(); if (enemyHealth != null) { if (Vector3.Distance(detonationPoint, hitCollider.transform.position) < blastRadius) { // find distance. float distance = Vector3.Distance(detonationPoint, hitCollider.transform.position); // find damage. int damage = -Mathf.RoundToInt(Mathf.Pow(distance / blastRadius, 2)) + maxDamage; // raycast to find the point where the blast hits. RaycastHit damageHit; Physics.Raycast(detonationPoint, (hitCollider.transform.position - detonationPoint), out damageHit); Vector3 hitPoint = damageHit.point; //Debug.DrawRay(detonationPoint, hitCollider.transform.position - detonationPoint, Color.red, Mathf.Infinity); Log.Debug("AirStrike", "damage: {0}, hitPoint: {1}, distance: {2}", damage, hitPoint, distance); // deal damage. enemyHealth.TakeDamage(damage, hitPoint); } } } isDetonated = true; Destroy(gameObject); }
void Impact() { Instantiate(Explo, transform.position, transform.rotation); Instantiate(fireEffect, transform.position, transform.rotation); Collider[] colliders = Physics.OverlapSphere(transform.position, radius); Debug.Log("I IS HEAR"); foreach (Collider nearbyObjects in colliders) { EnemyHealth enemyHealth = nearbyObjects.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damage); } } Destroy(gameObject); }
void Explode() { Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, 6, pLayerMask.value); foreach (Collider nearbyObject in collidersToDestroy) { EnemyHealth bodyZomb = nearbyObject.GetComponent <EnemyHealth>(); if (bodyZomb != null) { bodyZomb.TakeDamage(125, transform.position); } PlayerHealth bodyPlayer = nearbyObject.GetComponent <PlayerHealth>(); if (bodyPlayer != null && !bodyPlayer.isDead) { bodyPlayer.TakeDamage(125); } } }
void OnTriggerEnter(Collider col) { if (!HealthManager.instance.earthHealth.isDead) { if (Input.GetButton(attackButton_Win)) { Woosh.Play(); Invoke("Stop", 0.5f); } if (Input.GetButton(attackButton_Win) && col.gameObject.tag == "Enemy" || col.gameObject.tag == "IceBlock") { EnemyHealth enemyHealth = col.gameObject.GetComponent <EnemyHealth>(); Rigidbody rb = col.gameObject.GetComponent <Rigidbody>(); rb.AddForce(Vector3.forward * pushForce, ForceMode.Impulse); rb.constraints = RigidbodyConstraints.None; enemyHealth.TakeDamage(damagePerAttack); Invoke("StopFalling", .9f); } if (Input.GetButton(attackButton_Mac)) { Woosh.Play(); Invoke("Stop", 0.5f); } if (Input.GetButton(attackButton_Mac) && col.gameObject.tag == "Enemy" || col.gameObject.tag == "IceBlock") { EnemyHealth enemyHealth = col.gameObject.GetComponent <EnemyHealth>(); Rigidbody rb = col.gameObject.GetComponent <Rigidbody>(); rb.AddForce(Vector3.forward * pushForce, ForceMode.Impulse); rb.constraints = RigidbodyConstraints.None; enemyHealth.TakeDamage(damagePerAttack); Invoke("StopFalling", 0.9f); } } }
void CastShootRay(LineRenderer gunLine, Vector3 direction) { // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. Ray shootRay = new Ray(); // A ray from the gun end forwards. shootRay.origin = transform.position; shootRay.direction = direction; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } LuaFunction.FireEvent("ShootEnemy", shootHit.collider.gameObject.GetInstanceID(), damagePerShot, shootHit.point); // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
public int Shoot(Vector3 origin, Vector3 direction, out Vector3 destination) { Debug.Log("Shooting"); Debug.Log(origin); // Reset the timer. /*timer = 0f; * * // Play the gun shot audioclip. * gunAudio.Play (); * * // Enable the lights. * gunLight.enabled = true; * faceLight.enabled = true; * * // Stop the particles from playing if they were, then start the particles. * gunParticles.Stop (); * gunParticles.Play (); * * // Enable the line renderer and set it's first position to be the end of the gun. * gunLine.enabled = true; * gunLine.SetPosition (0, origin); */ // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = origin; shootRay.direction = direction; //destination = origin; int score = 0; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { if (PlayerManager.instance.startGame) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. score = enemyHealth.TakeDamage(damagePerShot, shootHit.point); } else { Debug.Log("No ennemy"); } } else { VRStandardAssets.ShootingGallery.ShootingTarget shootingTarget = shootHit.collider.GetComponent <VRStandardAssets.ShootingGallery.ShootingTarget>(); // If the EnemyHealth component exist... if (shootingTarget != null) { // ... the enemy should take damage. if (vrGun != null && transform.parent.parent.GetComponent <NetworkShoot>().isLocalPlayer) { //shootingTarget.ImReady(); score = -1; } else { score = -2; Debug.Log("Not local player"); } } else { Debug.Log("No ennemy"); } } // Set the second position of the line renderer to the point the raycast hit. //gunLine.SetPosition (1, shootHit.point); destination = shootHit.point; } // If the raycast didn't hit anything on the shootable layer... else { Debug.Log("Shooting fail"); // ... set the second position of the line renderer to the fullest extent of the gun's range. destination = shootRay.origin + shootRay.direction * range; } return(score); }
void Shoot() { if (!bulletExplosion) { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } } else { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; shootRayBack.origin = transform.position; shootRayBack.direction = transform.forward * -1; shootRayLeft.origin = transform.position; shootRayLeft.direction = transform.right * -1; shootRayRight.origin = transform.position; shootRayRight.direction = transform.right; shootRay45.origin = transform.position; shootRay45.direction = (transform.forward + transform.right).normalized; shootRayneg45.origin = transform.position; shootRayneg45.direction = (transform.forward - transform.right).normalized; shootRay135.origin = transform.position; shootRay135.direction = -(transform.forward + transform.right).normalized; shootRayneg135.origin = transform.position; shootRayneg135.direction = -(transform.forward - transform.right).normalized; if (Physics.Raycast(shootRayneg45, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRayneg45.origin + shootRayneg45.direction * range); } if (Physics.Raycast(shootRayneg135, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRayneg135.origin + shootRayneg135.direction * range); } if (Physics.Raycast(shootRay135, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay135.origin + shootRay135.direction * range); } if (Physics.Raycast(shootRayBack, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRayBack.origin + shootRayBack.direction * range); } if (Physics.Raycast(shootRayLeft, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRayLeft.origin + shootRayLeft.direction * range); } if (Physics.Raycast(shootRayRight, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRayRight.origin + shootRayRight.direction * range); } if (Physics.Raycast(shootRay45, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay45.origin + shootRay45.direction * range); } if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } } }
public void TakeDamageWithEffect(int Damage, Vector3 hitpoint) { HP.TakeDamage(Damage, hitpoint); }
void Shoot() { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; Vector3 finalPoint = new Vector3(); finalPoint.Set(0, 0, 0); float currentRange = range; if (onPower) { // Perform the raycast against gameobjects on the shootable layer and if it hits something... while ((range > 0) && (Physics.SphereCast(shootRay.origin, 1f, shootRay.direction, out shootHit, currentRange, shootableMask))) { //if(Physics.Raycast (shootRay, out shootHit, range, shootableMask)) // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. //gunLine.SetPosition (1, shootHit.point); finalPoint = shootHit.point + shootHit.normal.normalized + shootRay.direction.normalized; //gunLine.SetPosition (1, finalPoint); currentRange -= (finalPoint - shootRay.origin).magnitude; shootRay.origin = finalPoint; //gunLine.SetPosition (0, finalPoint); } gunLine.SetPosition(1, transform.position + shootRay.direction * range); } else { if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, transform.position + shootRay.direction * range); } } }
/* La función es la encargada realizar * el disparo del jugador, el cual se * encargda de emplear la trayectoria de * la bala con la función seno, y se * genera el daño por bala por medio de * la función coseno. */ void Shoot() { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLineCenter.enabled = true; // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); //PARA GENERAR DAÑO ALEATORIO int danoPorBala = 30; //Inicializamos el valor de daño por cada bala en 30 if (Application.loadedLevelName == "level2") //Si se encuentra en el nivel2 el daño por bala va a ser siempre 100 { damagePerShot = 100; //Toma el valor de 100 } else // si estamos en el nivel1 //Aplicamos la función cosenos para asignar daño por bala { float funcionCos = Mathf.Cos(Random.Range(-Mathf.PI / 2, Mathf.PI / 2)); int danoF = (int)(funcionCos * 100); //Multiplixamos por 100 dado a que la función Coseno toma valores entre [0-1] if (danoF <= danoPorBala) //Si es menor a 30 entonces asignamos el número aleatorio a daño por bala { damagePerShot = danoF; //se asigna el valor al la variable daño } else //Si es mayor a 30 asignamos 30 a daño por bala { damagePerShot = danoPorBala; } } //Fin generar daño aleatorio // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. Vector3 dir = (shootHit.point - transform.position).normalized; Vector3[] points = new Vector3[lengthOfLineRenderer]; // se crea un arreglo de vectores de 3 dimensiones, donde se guardara cada vertice de la linea float t = Time.time; float tamanoDivisiones = (shootHit.point - transform.position).magnitude / lengthOfLineRenderer; int i = 1; points [0] = transform.position; while (i < lengthOfLineRenderer) { points[i] = new Vector3((i * tamanoDivisiones * dir.x) + transform.position.x, shootHit.point.y, (Mathf.Sin(i + t)) + (i * tamanoDivisiones * dir.z) + transform.position.z); i++; } gunLine.SetPositions(points); // crea una linea por todos los vertices guardados en el arreglo } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void Shoot() { if (currentBullets <= 0) { return; } currentBullets--; ammoSlider.value = currentBullets; // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); enemyImage.enabled = true; enemyImage.sprite = enemyHealth.icon; enemyHealthSlider.gameObject.SetActive(true); enemyHealthSlider.value = enemyHealth.GetHealthPercentage(); StopCoroutine(ScheduleHideEnemyUI()); StartCoroutine(ScheduleHideEnemyUI()); } else { HideEnemyUI(); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void Shoot() { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } Dictionary <string, object> eventProperty = new TrackPropertyBuilder() .SetCategory("PlayerShooting_Shoot") .Build(); eventProperty.Add("dummy_e_prop_1", "dummy_e_prop_1_value"); eventProperty.Add("dummy_e_prop_2", "dummy_e_prop_2_value"); eventProperty.Add("dummy_e_prop_3", "dummy_e_prop_3_value"); eventProperty.Add("score", ScoreManager.score); Dictionary <string, object> userProperty = new Dictionary <string, object> (); userProperty.Add("dummy_prop_1", "dummp_prop_1_value"); userProperty.Add("dummy_prop_2", "dummp_prop_2_value"); RudderElement element = new RudderElementBuilder() .WithEventName("PlayerShooting_Shoot") .WithUserId("test_user_id_sayan_android") .WithEventProperties(eventProperty) .WithUserProperties(userProperty) .Build(); element.integrations = new Dictionary <string, object>(); element.integrations.Add("All", false); element.integrations.Add("AM", true); element.integrations.Add("GA", true); PlayerMovement.rudderClient.Track(element); }
void Shoot() { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; EnemyHealth enemyHealth = null; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } Debug.Log("Tracking Shoot"); RudderEvent rudderEvent = new RudderEventBuilder() .SetEventName("PlayerShooting_Shoot") .SetUserId("w240adxe7fseasn34m6u-4vpw1n7iac2jz9b135s7") .Build(); RudderProperty rudderProperty = new RudderProperty(); rudderProperty.AddProperty("category", "Shoot"); rudderProperty.AddProperty("transform_position", transform.position.ToString()); if (enemyHealth != null) { rudderProperty.AddProperty("enemy_health", enemyHealth.currentHealth.ToString()); } rudderEvent.SetProperties(rudderProperty); rudderEvent.AddIntegrations(RudderIntegrationPlatform.ALL, false); rudderEvent.AddIntegrations(RudderIntegrationPlatform.GOOGLE_ANALYTICS, true); rudderEvent.AddIntegrations(RudderIntegrationPlatform.AMPLITUDE, true); CompleteProject.PlayerMovement.rudderInstance.Track(rudderEvent); // Dictionary<string, object> demoOptions = new Dictionary<string, object>() { // {"category" , "Shoot" }, // {"transform_position" , transform.position.ToString()}, // {"rl_message_id" , rudderEvent.rl_message.rl_message_id} // }; // if (enemyHealth != null) // { // demoOptions.Add("enemy_health", enemyHealth.currentHealth); // } // Amplitude.Instance.logEvent("PlayerShooting_Shoot Direct", demoOptions); }
void Shoot() { shot++; //int shot = 0; timer = 0f; int randomclip = Random.Range(0, shotClips.Count); Debug.Log("OnTriggerEnter" + Time.time); float randomVol = Random.Range(0.3f, 0.8f); aSource.volume = randomVol; float randomPitch = Random.Range(1, 3); aSource.pitch = randomPitch; SingleShot(); if (shot % 3 == 0) { for (int shot = 0; shot <= 2; shot++) { Invoke("Shell", shot * 0.2f); } } /*if(shot < 4){ //how to check specific clip? * * aSource.PlayOneShot(shotClips[randomclip]); * * if(shot == 3){ * for(int shot = 0; shot <= 2; shot++) * { * aSource.PlayOneShot(shellClips[randomclip]); * aSource.clip = shellClips[randomclip]; * * } * Invoke("PauseSound", 3f); * //need to pause animation * //aSource.PlayDelayed(1f); * } * } */ /* for(int shot = 0; shot <= 2; shot++) * { * Invoke("SingleShot", shot); * } * Invoke("PauseSound", 3f);*/ // ignore mouse press until shells finished playing // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }