void OnCollisionEnter(Collision other) { List <Vector3> particlePos = new List <Vector3>(); List <Vector3> particleAngle = new List <Vector3>(); var rot = Quaternion.FromToRotation(Vector3.up, other.contacts[0].normal); Destroy(Instantiate(humanBlood.gameObject, other.contacts[0].point, rot), 2f); particlePos.Add(other.contacts[0].point); particleAngle.Add(rot.eulerAngles); RequestHit requestHit = new RequestHit(); requestHit.setData(other.gameObject.tag, (int)AttackDamage, 1, particlePos, particleAngle); requestHit.send(); Main.GetConnectionManager().send(requestHit); }
public void Shoot() { // List of particle positions and angles to send to server List <Vector3> particlePos = new List <Vector3>(); List <Vector3> particleAngle = new List <Vector3>(); RaycastHit hit; equip = hud.gunEquipped; bool playAnimation = false; if (hud.ammoIn > 0 && Time.time > nextFire) { // Update the time when our player can fire next nextFire = Time.time + gun_stats[equip].fireRate; //Update HUD hud.AmmoCounter(1); // Conditions for if statement // 1. Input returns true when left click down and false when released // 2. Send out raycast straight forward from player camera // 3. Check if raycast hit Bog lord // 4. Applying pistol fire rate if ((equip == "Pistol" | equip == "AK-47") && Physics.Raycast(this.transform.position, this.transform.forward, out hit, gun_stats[equip].range) && hit.collider.gameObject.tag == "Bog_lord") { // Trigger Bog_lord isHit animation playAnimation = true; // spawn monsterBlood particle effect, then destroy clone gameObject var rot = Quaternion.FromToRotation(Vector3.up, hit.normal); Destroy(Instantiate(monsterBlood.gameObject, hit.point, rot), 2f); particlePos.Add(hit.point); particleAngle.Add(rot.eulerAngles); RequestHit requestHit = new RequestHit(); requestHit.setData(Constants.MONSTER, gun_stats[equip].damage, 1, particlePos, particleAngle); requestHit.send(); Main.GetConnectionManager().send(requestHit); Debug.Log("Bog lord has been shot with pistol/ak-47!"); } if (equip == "Shotgun") { int raysHit = 0; for (var i = 0; i < 30; i++) { Vector3 v3Offset = transform.up * Random.Range(0.0f, variance); v3Offset = Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), transform.forward) * v3Offset; Vector3 v3Hit = transform.forward * distance + v3Offset; // shotgunRays.Add(v3Hit); // will add up shotgun spread rays that hit Bog lord to apply the total as damage to Bog lord if (Physics.Raycast(this.transform.position, v3Hit, out hit, gun_stats[equip].range) && hit.collider.gameObject.tag == "Bog_lord") { // spawn monsterBlood particle effect, then destroy clone gameObject var rot = Quaternion.FromToRotation(Vector3.up, hit.normal); Destroy(Instantiate(monsterBlood.gameObject, hit.point, rot), 2f); playAnimation = true; particlePos.Add(hit.point); particleAngle.Add(rot.eulerAngles); raysHit += 1; } } RequestHit requestHit = new RequestHit(); requestHit.setData(Constants.MONSTER, raysHit, raysHit, particlePos, particleAngle); requestHit.send(); Main.GetConnectionManager().send(requestHit); //Instantiate(monsterBlood, hit.collider.gameObject.transform) // applyDmgBog(raysHit); Debug.Log(raysHit); Debug.Log("Bog lord has been shot with shotgun!"); } if (playAnimation) { // Needs to be fixed. Monster gets stuck in isHit animation //anim.SetBool("isHit", true); } } }