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(); } } } }
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; } }