public void TakeDamage() { Debug.Log("AAA"); // Instantiate(EfectoHit, transform.position, Quaternion.identity); cam.TryShake(0.1f, 0.1f); Lives--; DropWeapon(false); //DEATH GameObject @object = Instantiate(dummy, transform.position, Quaternion.Euler(0, 0, tilt * multiplier)); @object.GetComponent <Rigidbody2D>().velocity = rb.velocity; @object.GetComponent <Rigidbody2D>().AddForce(rb.velocity); if (Lives == 0) { } Destroy(gameObject); if (Lives > 0) { @object.GetComponent <autodestroy>().doIt = true; //still } else { @object.GetComponent <autodestroy>().doIt = false; //Lose } }
public void Update() { if (withRaycast) { RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, -multiplier * Range); if (hitInfo) { Movement enemy = hitInfo.transform.GetComponent <Movement>(); if (enemy != null && !enemy.CompareTag(objectTag)) { cam.TryShake(0.1f, 0.1f); enemy.TakeDamage(true, Push); } } } if (Vector2.Distance(FirePoint, transform.position) > Range) { Destroy(gameObject); } }
IEnumerator Shoot() { if (Ammo > 0) { //(new Vector2(knockback, 0.1f)); Vector3 ndeah = FirePoint.position; ndeah.z -= 50; Ammo--; if (FloatingText != null) { FloatingText.GetComponent <TextMesh>().text = Ammo.ToString(); } if (!IsGranade) { if (cam != null) { cam.TryShake(0.1f, 0.1f); } bullet Script = bulletPrefab.GetComponent <bullet>(); Script.ImpactEffect = ImpactEffect; Script.objectTag = objectTag; Script.speed = speed; Script.multiplier = multiplier; Script.Push = Push; Script.cam = cam; Script.Range = Range; Script.ProjectileSpread = ProjectileSpread * 10; Script.withRaycast = wantRaycast; float random = Random.Range(-ProjectileSpread, ProjectileSpread); Quaternion quat = new Quaternion(0, 0, random, 0); Instantiate(bulletPrefab, FirePoint.position, quat); Vector2 vel = control.GetComponent <Rigidbody2D>().velocity; vel.x -= knockback * multiplier; vel.y -= 0.1f * multiplier; control.GetComponent <Rigidbody2D>().velocity = vel; if (ImpactEffect != null) { Instantiate(ImpactEffect, ndeah, Quaternion.identity); } } else { if (first) { first = false; yield return(new WaitForSeconds(GranadeTime)); if (ImpactEffect != null) { Instantiate(ImpactEffect, ndeah, Quaternion.identity); } Collider2D[] enemys = Physics2D.OverlapCircleAll(FirePoint.position, Range, WhatissolidGranade); for (int i = 0; i < enemys.Length; i++) { enemys[i].GetComponent <Movement>().TakeDamage(true, Push); } Destroy(gameObject); } else { pj.DropWeapon(false); Gravity.velocity = new Vector2(ForceRight * multiplier, ForceUp); gameObject.GetComponent <Collider2D>().sharedMaterial = mat; } } } else { //Sin municion if (EmptyEffect != null) { Vector3 ndeah = FirePoint.position; //ndeah.z -= 50; Instantiate(EmptyEffect, ndeah, Quaternion.identity); } //EmptyEffect() } }