void OnTriggerEnter2D(Collider2D other) { if (Vector3.Distance(player.transform.position, this.gameObject.transform.position) < 1.1f && other.gameObject.tag == "Enemy") { EnemyAttacked ea = other.gameObject.GetComponent <EnemyAttacked> (); ea.knockDownEnemy(); } }
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Enemy") { if (Vector3.Distance(player.transform.position, this.transform.position) < 1.0) { EnemyAttacked ea = coll.gameObject.GetComponent <EnemyAttacked> (); ea.knockDownEnemy(); } } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Enemy") { attacked = col.gameObject.GetComponent <EnemyAttacked> (); attacked.knockDownEnemy(); int level; if (sceneName == "Tutorial") { level = 0; } else { level = Utils.LevelFromSceneName(sceneName); } Debug.Log("nivel de Noquear: " + level); Debug.Log("Enemigo de Noquear con arma: " + attacked.nombreEnemigo); Debug.Log("tiempo de Noquear: " + Time.timeSinceLevelLoad); Debug.Log("Insertar evento de noquear"); /* PROBLEMA EN EL COLLIDER PORQUE LO TOMA MAS DE UNA VEZ * Analytics.CustomEvent("Noquear", new Dictionary<string, object> * { { "nivel", level }, * { "enemigo", attacked.nombreEnemigo }, * { "tiempo", Time.timeSinceLevelLoad } * } * ); */ rid.isKinematic = true; Destroy(this); } else if (col.gameObject.tag == "Player") { } else if (col.gameObject.tag == "Dog") { col.gameObject.GetComponent <DogHealth> ().killDog(); } else if (col.gameObject.tag == "Wall") { rid.velocity = new Vector3(0, 0, 0); } else { rid.isKinematic = true; Destroy(this); } }
public void attack() { pa.attack(); if (gun == true) { //Bullet bl = bullet.GetComponent<Bullet> ();//creation of bullet with own direction set Vector3 dir; dir.x = Vector2.right.x; //rotation of bullet dir.y = Vector2.right.y; dir.z = 0; bl.setVals(dir, "Player"); //knows who created the bullet if (oneHanded == true) { Instantiate(bl, oneHandSpawn.transform.position, this.transform.rotation); } else { Instantiate(bl, twoHandSpawn.transform.position, this.transform.rotation); } this.GetComponent <AudioController> ().fireSmg(); timer = timerReset; } else { //melee attack int layerMask = 1 << 9; layerMask = ~layerMask; pa.attack(); RaycastHit2D ray = Physics2D.Raycast(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), 1.5f, layerMask); //create a line from the player wich can hit an enemy Debug.DrawRay(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), Color.green); if (curWeapon == null && ray.collider.gameObject.tag == "Enemy") // if player doesn't hold any weapon and the player sight line (ray) hits enemy, { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked> (); ea.knockDownEnemy(); this.GetComponent <AudioController> ().meleeAttack(); } else if (ray.collider != null) { if (ray.collider.gameObject.tag == "Enemy") //if player have meelee weapon -> instant kill { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked> (); ea.killMelee(); this.GetComponent <AudioController> ().meleeAttack(); } } } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Enemy") { attacked = col.gameObject.GetComponent <EnemyAttacked>(); attacked.knockDownEnemy(); rid.isKinematic = true; Destroy(this); } else if (col.gameObject.tag == "Player") { } else { rid.isKinematic = true; Destroy(this); } }
public void attack() { int layerMask = 1 << 9; layerMask = ~layerMask; pa.attack(); RaycastHit2D ray = Physics2D.Raycast(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.up.x, transform.up.y), 1.5f, layerMask); Debug.DrawRay(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.up.x, transform.up.y)); if (curWeapon == null && ray.collider.gameObject.tag == "Enemy") { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked>(); ea.knockDownEnemy(); } else if (ray.collider != null) { Debug.Log(ray.collider.gameObject.tag); if (ray.collider.gameObject.tag == "Enemy") { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked>(); ea.killMelee(); } } }
public void attack() { if (gun == true && curWepScr.ammo > 0) //NEW STUFF FOR 16 { pa.attack(); Bullet bl = bullet.GetComponent <Bullet> (); Vector3 dir; dir.x = Vector2.right.x; dir.y = Vector2.right.y; dir.z = 0; bl.setVals(dir, "Player"); if (oneHanded == true) { if (Shotgun == false) //new for new weapons { Instantiate(bullet, oneHandSpawn.transform.position, this.transform.rotation); } else { Instantiate(shotgunBullet, oneHandSpawn.transform.position, this.transform.rotation); } curWeapon.GetComponent <WeaponPickup> ().ammo--; FindObjectOfType <LevelEscapeController> ().shotFired(); } else { if (Shotgun == false) //new for new weapons { Instantiate(bullet, twoHandSpawn.transform.position, this.transform.rotation); } else { Instantiate(shotgunBullet, twoHandSpawn.transform.position, this.transform.rotation); } curWeapon.GetComponent <WeaponPickup> ().ammo--; FindObjectOfType <LevelEscapeController> ().shotFired(); } decideSFX(); timer = timerReset; //if (Input.GetMouseButtonUp (0)) { //pa.resetCounter (); //} } else if (gun == true && curWepScr.ammo == 0) { //NEW STUFF FOR 16 } else { pa.attack(); //NEW STUFF FOR 16 //melee attack int layerMask = 1 << 9; layerMask = ~layerMask; pa.attack(); RaycastHit2D ray = Physics2D.Raycast(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), 1.5f, layerMask); Debug.DrawRay(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), Color.green); if (ray.collider == null) { } else { if (curWeapon == null && ray.collider.gameObject.tag == "Enemy") { if (ray.collider.isTrigger == true && ray.collider.gameObject.tag == "Enemy") //new for execute { ray.collider.gameObject.GetComponent <EnemyAttacked> ().execute(); decideSFX(); } else { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked> (); ea.knockDownEnemy(); decideSFX(); } } else if (curWeapon == null && ray.collider.gameObject.tag == "Dog") //// { ray.collider.gameObject.GetComponent <DogHealth> ().killDog(); // } // else if (curWeapon == null && ray.collider.gameObject.tag == "Wall" && ray.collider.gameObject.GetComponent <Window> () != null) { ray.collider.gameObject.GetComponent <Window> ().breakWindow(); } else if (ray.collider != null) { Debug.Log(ray.collider.gameObject.tag); if (ray.collider.gameObject.tag == "Enemy") { if (ray.collider.isTrigger == true && ray.collider.gameObject.tag == "Enemy") { ray.collider.gameObject.GetComponent <EnemyAttacked> ().execute(); } else { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked> (); ea.killMelee(); decideSFX(); } } else if (ray.collider.gameObject.tag == "Dog") { ray.collider.gameObject.GetComponent <DogHealth> ().killDog(); } if (ray.collider.gameObject.tag == "Wall" && ray.collider.gameObject.GetComponent <Window> () != null) { ray.collider.gameObject.GetComponent <Window> ().breakWindow(); } } } timer = timerReset; } }
public void attack() { if (gun == true && curWepScr.ammo > 0) { //NEW STUFF FOR 16 pa.attack(); Vector3 dir; dir.x = Vector2.right.x; dir.y = Vector2.right.y; dir.z = 0; if (oneHanded == true) { if (Shotgun == false) { //new for new weapons Bullet bl = Instantiate(bullet, oneHandSpawn.transform.position, this.transform.rotation).GetComponent <Bullet>(); bl.arma = curWepScr.name; ContarMuertos.armaPlayer = bl.arma; //Pasa el arma para el evento Matar Debug.Log("El arma del player es: " + bl.arma); } else { //Instantiate (shotgunBullet, oneHandSpawn.transform.position, this.transform.rotation); Linea comentada para prueba //Comienzo prueba GameObject go = Instantiate(shotgunBullet, oneHandSpawn.transform.position, this.transform.rotation); Bullet[] bullets = go.GetComponentsInChildren <Bullet>(); foreach (Bullet b in bullets) { b.arma = curWepScr.name; // o el arma que sea Debug.Log("El arma del player es: " + b.arma); ContarMuertos.armaPlayer = b.arma; } //Finaliza prueba } curWeapon.GetComponent <WeaponPickup> ().ammo--; //FindObjectOfType<LevelEscapeController> ().shotFired (); Comentado para que se pueda disparar } else { if (Shotgun == false) { //new for new weapons Bullet bl = Instantiate(bullet, twoHandSpawn.transform.position, this.transform.rotation).GetComponent <Bullet>(); bl.arma = curWepScr.name; Debug.Log("El arma del player es: " + bl.arma); } else { //Instantiate (shotgunBullet, twoHandSpawn.transform.position, this.transform.rotation); //Comienzo prueba GameObject go = Instantiate(shotgunBullet, oneHandSpawn.transform.position, this.transform.rotation); Bullet[] bullets = go.GetComponentsInChildren <Bullet>(); foreach (Bullet b in bullets) { b.arma = curWepScr.name; // o el arma que sea Debug.Log("El arma del player es: " + b.arma); ContarMuertos.armaPlayer = b.arma; } //Finaliza prueba } curWeapon.GetComponent <WeaponPickup> ().ammo--; FindObjectOfType <LevelEscapeController> ().shotFired(); } decideSFX(); timer = timerReset; //if (Input.GetMouseButtonUp (0)) { //pa.resetCounter (); //} } else if (gun == true && curWepScr.ammo == 0) { //NEW STUFF FOR 16 } else { pa.attack(); //NEW STUFF FOR 16 //melee attack int layerMask = 1 << 9; layerMask = ~layerMask; pa.attack(); RaycastHit2D ray = Physics2D.Raycast(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), 1.5f, layerMask); Debug.DrawRay(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), Color.green); if (ray.collider == null) { } else { if (curWeapon == null && ray.collider.gameObject.tag == "Enemy") { if (ray.collider.isTrigger == true && ray.collider.gameObject.tag == "Enemy") { //new for execute ray.collider.gameObject.GetComponent <EnemyAttacked> ().execute(); if (curWepScr == null) { ContarMuertos.armaPlayer = "sin arma"; Debug.Log("Enemigo murio " + ContarMuertos.armaPlayer); } else if (curWepScr != null) { ContarMuertos.armaPlayer = curWepScr.name; Debug.Log("Enemigo murio con arma: " + ContarMuertos.armaPlayer); } decideSFX(); } else { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked> (); ea.knockDownEnemy(); int level; if (sceneName == "Tutorial") { level = 0; } else { level = Utils.LevelFromSceneName(sceneName); } Debug.Log("nivel de Noquear: " + level); Debug.Log("Enemigo de Noquear sin arma: " + ea.nombreEnemigo); Debug.Log("tiempo de Noquear: " + Time.timeSinceLevelLoad); Debug.Log("Insertar evento de noquear"); Analytics.CustomEvent("Noquear", new Dictionary <string, object> { { "nivel", level }, { "enemigo", ea.nombreEnemigo }, { "tiempo", Time.timeSinceLevelLoad } } ); decideSFX(); } } else if (curWeapon == null && ray.collider.gameObject.tag == "Dog") { //// ray.collider.gameObject.GetComponent <DogHealth> ().killDog(); // } // else if (curWeapon == null && ray.collider.gameObject.tag == "Wall" && ray.collider.gameObject.GetComponent <Window> () != null) { ray.collider.gameObject.GetComponent <Window> ().breakWindow(); } else if (ray.collider != null) { //Debug.Log (ray.collider.gameObject.tag); if (ray.collider.gameObject.tag == "Enemy") { if (ray.collider.isTrigger == true && ray.collider.gameObject.tag == "Enemy") { ray.collider.gameObject.GetComponent <EnemyAttacked> ().execute(); if (curWepScr == null) { ContarMuertos.armaPlayer = "sin arma"; Debug.Log("Enemigo murio " + ContarMuertos.armaPlayer); } else if (curWepScr != null) { ContarMuertos.armaPlayer = curWepScr.name; Debug.Log("Enemigo murio con arma: " + ContarMuertos.armaPlayer); } } else { EnemyAttacked ea = ray.collider.gameObject.GetComponent <EnemyAttacked> (); ea.killMelee(); if (curWepScr == null) { ContarMuertos.armaPlayer = "sin arma"; Debug.Log("Enemigo murio " + ContarMuertos.armaPlayer); } else if (curWepScr != null) { ContarMuertos.armaPlayer = curWepScr.name; Debug.Log("Enemigo murio con arma: " + ContarMuertos.armaPlayer); } decideSFX(); } } else if (ray.collider.gameObject.tag == "Dog") { ray.collider.gameObject.GetComponent <DogHealth> ().killDog(); } if (ray.collider.gameObject.tag == "Wall" && ray.collider.gameObject.GetComponent <Window> () != null) { ray.collider.gameObject.GetComponent <Window> ().breakWindow(); } } } timer = timerReset; } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Enemy") { attacked = col.gameObject.GetComponent <EnemyAttacked> (); attacked.knockDownEnemy(); int level; if (sceneName == "Tutorial") { level = 0; } else { level = Utils.LevelFromSceneName(sceneName); } if (GameManager.ultimoEnemigoNoqueadoConArma != attacked.nombreEnemigo) { Debug.Log("nivel de Noquear: " + level); Debug.Log("Nombre de enemigo noqueado: " + attacked.nombreEnemigo); Debug.Log("tiempo de Noquear: " + Time.timeSinceLevelLoad); WeaponPickup weapon = this.GetComponent <WeaponPickup>(); Debug.Log("arma de Noquear: " + weapon.name); Debug.Log("Insertar evento de noquear arrojando arma"); switch (weapon.name) { case "Bowie": GameManager.noquearBowie += 1; break; case "Colt": GameManager.noquearColt += 1; break; case "Mac10": GameManager.noquearMac10 += 1; break; case "Bat": GameManager.noquearBat += 1; break; case "Thompson": GameManager.noquearThompson += 1; break; case "SawnOff": GameManager.noquearSawnOff += 1; break; case "Winchester": GameManager.noquearWinchester += 1; break; case "Matute": GameManager.noquearMatute += 1; break; default: break; } Analytics.CustomEvent("Noquear", new Dictionary <string, object> { { "nivel", level }, { "enemigo", attacked.nombreEnemigo }, { "tiempo", Time.timeSinceLevelLoad } } ); GameManager.ultimoEnemigoNoqueadoConArma = attacked.nombreEnemigo; } rid.isKinematic = true; Destroy(this); } else if (col.gameObject.tag == "Player") { } else if (col.gameObject.tag == "Dog") { col.gameObject.GetComponent <DogHealth> ().killDog(); } else if (col.gameObject.tag == "Wall") { rid.velocity = new Vector3(0, 0, 0); } else { rid.isKinematic = true; Destroy(this); } }