// Update is called once per frame void Update() { //if left click if (Input.GetMouseButtonDown(0) && _canFire == true) { _canFire = false; _anim.SetTrigger("Fire"); _source.Play(); _smokeParticle.Emit(5); _tracer.Emit(10); _muzzleFlash.Emit(1); StartCoroutine(WeaponCoolDownRoutine()); //cast ray from center of the screen through the radicule Ray rayOrigin = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f)); RaycastHit hitInfo; //Store information about the object we hit //cast a ray if (Physics.Raycast(rayOrigin, out hitInfo)) { EnemyAI enemy = hitInfo.collider.GetComponent <EnemyAI>(); if (enemy != null) { GameObject blood = Instantiate(_bloodSplat, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); Destroy(blood, 5.0f); enemy.Damage(20); } } } }
IEnumerator RaycastShoot() { RaycastHit2D HitInfo = Physics2D.Raycast(FirePoint01.position, FirePoint01.right); //Uses raycast to draw a line from the player (fire point) in the direction of the gun if (HitInfo && HitInfo.collider.tag != "Player" && HitInfo.collider.tag != "Stun" && HitInfo.collider.tag != "Bullet" && HitInfo.collider.tag != "StunCollider") //If the raycast detects something that isn't tagged as player { EnemyAI Enemy = HitInfo.transform.GetComponent <EnemyAI>(); //Get the Enemy game component if (Enemy != null) //If an enemy is detected { Enemy.Damage(GM.PlayerGunDamage); //Call Takedamage function in the enemy script and send the Gun Damage variable } Instantiate(ImpactEffect, HitInfo.point, Quaternion.identity); //Make an Impact effect, Where the bullet is, With locked rotation LineRend.SetPosition(0, FirePoint01.position); //Sets first point of the line on the fire point position LineRend.SetPosition(1, HitInfo.point); //Sets second point of the line at the detected object } else { LineRend.SetPosition(0, FirePoint01.position); //Sets first point of the line on the fire point position LineRend.SetPosition(1, FirePoint01.position + FirePoint01.right * 100); //Sets the second point of the line 100 units away from the firepoint in the direction of the gun } LineRend.enabled = true; //Draw the line yield return(new WaitForSeconds(0.02f)); //Wait for 0.02 seconds LineRend.enabled = false; //Hide the line }
void Update() { //disparo if (Input.GetMouseButtonDown(0) && _canFire == true) { _canFire = false; _anim.SetTrigger("Fire"); _source.Play(); _smokeParticle.Emit(5); _tracer.Emit(10); _muzzleFlash.Emit(1); StartCoroutine(WeaponCoolDownRoutine()); //fogonazo Ray rayOrigin = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f)); RaycastHit hitInfo; //almacenar daño if (Physics.Raycast(rayOrigin, out hitInfo)) { EnemyAI enemy = hitInfo.collider.GetComponent <EnemyAI>(); // if (enemy != null) { //activar la sangre GameObject blood = Instantiate(_bloodSplat, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); enemy.Damage(34); } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag != "Obstacle") { EnemyAI enemyScript = collision.GetComponent <EnemyAI>(); if (enemyScript != null) // Si se ha golpeado a un enemigo { enemyScript.Damage(true); } Destroy(gameObject); } }
void OnCollisionEnter(Collision collision) { ContactPoint contact = collision.contacts[0]; target = collision.gameObject; refPos = contact.point - target.transform.position; //sticked = true; Physics.IgnoreCollision(gameObject.GetComponent <Collider>(), GetComponent <Collider>()); //Output the Collider's GameObject's name if (hit != 1) { Destroy(gameObject, 0f); //ShootableBox boxHealth = target.GetComponent<ShootableBox>(); EnemyAI health = target.GetComponent <EnemyAI>(); if (health != null) { health.Damage(damage); } hit = 1; } Debug.Log(collision.collider.name); }