public void KeyboardMovement() { if (!ctrl.isGrounded) { movement.y += Physics.gravity.y * Time.deltaTime; } // Jeśli gracz nie stoi na ziemi to grawitacja działa. if (Input.GetKeyDown(KeyCode.Space) && ctrl.isGrounded) //Skakanie { movement.y = jumpFactor; AudioSourceHandlerScript.PlayAudio(JumpAudioClip, transform.position, 1.0f); } if (Input.GetKeyDown(KeyCode.LeftShift)) { speed = 20.0f; } //Bieganie ON if (Input.GetKeyUp(KeyCode.LeftShift)) { speed = 8.5f; } //Bieganie OFF if (ctrl.isGrounded) //Pobieranie inputu { movement.z = Input.GetAxis("Vertical") * speed * transform.forward.z - Input.GetAxis("Horizontal") * speed * transform.forward.x; movement.x = Input.GetAxis("Vertical") * speed * transform.forward.x + Input.GetAxis("Horizontal") * speed * transform.forward.z; } ctrl.Move(movement * Time.deltaTime); if (ctrl.isGrounded && Vector3.Distance(transform.position, LastPlayerPosition) > StepDistance) { AudioSourceHandlerScript.PlayAudio(WalkAudioClip, transform.position, Random.Range(0.8f, 1.2f), Random.Range(-0.5f, 0.5f)); LastPlayerPosition = transform.position; } }
void BulletImpactDetection() { //WYKRYWANIE UDERZENIA Ray GunRay = new Ray(GunBarrelPosition.transform.position, GunBarrelPosition.transform.forward); Debug.DrawRay(GunBarrelPosition.transform.position, GunBarrelPosition.transform.forward * GunRange); //STRZELANIE RAYCASTEM if (Physics.Raycast(GunRay, out hit, GunRange)) { // Find the line from the gun to the point that was clicked. Vector3 incomingVec = hit.point - GunBarrelPosition.transform.position; // Use the point's normal to calculate the reflection vector. Vector3 reflectVec = Vector3.Reflect(incomingVec, hit.normal); Debug.DrawRay(hit.point, reflectVec); Instantiate(GunParticles, hit.point, Quaternion.LookRotation(reflectVec)); GameObject NewRayCastPinpoint = Instantiate(RayCastPinpointObject, hit.point + hit.normal.normalized / 50.0f, Quaternion.LookRotation(hit.normal)); NewRayCastPinpoint.transform.SetParent(hit.collider.transform); if (hit.collider.tag == "NPC") { hit.collider.gameObject.GetComponent <npcMove>().DestroyNavMesh(); } try { hit.collider.gameObject.GetComponent <Rigidbody>().AddForce(GunRay.direction * 200 * GunDamage); } catch (System.Exception) { } try { hit.collider.gameObject.GetComponent <ColliderScript>().skrypt.DamageHandler(hit.collider.gameObject.GetComponent <ColliderScript>().name, "bullet"); } catch (System.Exception) { } AudioSourceHandlerScript.PlayAudio(BulletImpactClip, hit.point, Random.Range(0.5f, 1.5f)); } }
public void AddGun(GameObject GunToAdd) { GameObject AddedGun = Instantiate(GunToAdd, Movement.BackItemPosition.transform.position, Movement.BackItemPosition.transform.rotation); AddedGun.GetComponent <Rigidbody>().isKinematic = true; AddedGun.GetComponent <Rigidbody>().useGravity = false; //Debug.Log("Podniesiono " + AddedGun.GetComponent<Gun>().Type + " health:" + AddedGun.GetComponent<Gun>().Health + " ammo: " + AddedGun.GetComponent<Gun>().AmmoLoaded); AddedGun.transform.position = Movement.BackItemPosition.transform.position; AddedGun.transform.rotation = Movement.BackItemPosition.transform.rotation; AddedGun.transform.SetParent(Movement.BackItemPosition.transform); AudioSourceHandlerScript.PlayAudio(Movement.GunPickUpAudioClip, transform.position, 1.0f); ItemsList.Add(AddedGun); }
public void Shot() { if (AmmoLoaded > 0) { Debug.Log("Strzeliles z :" + Type); GetComponent <Animation>().Stop(); GetComponent <Animation>().Play("Shoot"); if (Type != GunType.meelee) { AmmoLoaded -= 1; } AudioSourceHandlerScript.PlayAudio(ShotClip, transform.position, 1.0f); BulletImpactDetection(); } else { Debug.Log("BRAK AMMO!"); AudioSourceHandlerScript.PlayAudio(NoAmmoClip, transform.position, 1.0f); } }
public void SetItemActive() { ItemsList[SelectedItem].transform.position = Movement.CurrentItemPosition.transform.position; ItemsList[SelectedItem].transform.rotation = Movement.CurrentItemPosition.transform.rotation; ItemsList[SelectedItem].transform.SetParent(Movement.CurrentItemPosition.transform); if (ItemsList[SelectedItem].GetComponent <Gun>()) { ActiveItem = ItemsList[SelectedItem]; ActiveItem.GetComponent <Animation>().Play("Idle"); HealthUiText.text = ActiveItem.GetComponent <Gun>().Health.ToString(); if (ActiveItem.GetComponent <Gun>().Type != GunType.meelee) { AmmoUiText.text = ActiveItem.GetComponent <Gun>().AmmoLoaded.ToString(); } TypeUiText.text = ActiveItem.GetComponent <Gun>().Type.ToString(); AudioSourceHandlerScript.PlayAudio(GunSelect, transform.position, 1.0f); } else if (ItemsList[SelectedItem].GetComponent <GunAmmo>()) { ActiveItem = ItemsList[SelectedItem]; AudioSourceHandlerScript.PlayAudio(GunSelect, transform.position, 1.0f); } }
public void OnControllerColliderHit(ControllerColliderHit hit) { Rigidbody body = hit.collider.attachedRigidbody; //Pobranie rigidbody z ciała uderzanego if (!ctrl.isGrounded) //FallDamage { if (ctrl.velocity.magnitude > fallDamage_MinMagnitude) { character.Health -= (int)(ctrl.velocity.magnitude * fallDamage_Factor); Debug.Log("Walnales w ziemie z sila: " + ctrl.velocity.magnitude); AudioSourceHandlerScript.PlayAudio(FallDamageAudioClip, transform.position, 1.0f); character.HealthUiText.text = character.Health.ToString(); } } if (body == null || body.isKinematic || hit.moveDirection.y < -0.3f) //Odepchięcie ciała uderzonego { } else { Vector3 pushDir = new Vector3(hit.moveDirection.x, 0f, 0f); body.velocity = pushDir * pushPower; } } //FALL DAMAGE
private void OnCollisionEnter(Collision collision) { Debug.Log("GUN KOLIDUJE z siłą" + collision.relativeVelocity.magnitude); AudioSourceHandlerScript.PlayAudio(GunDrop, transform.position, Random.Range(0.8f, 1.2f), 0, collision.relativeVelocity.magnitude / 40.0f); }
public void Reload(int amount) { AmmoLoaded += amount; AudioSourceHandlerScript.PlayAudio(ReloadClip, transform.position, 1.0f); }
public void CharacterInteractionRaycast() { //Aktualizacja nowego raya landingRay.origin = FPCamera.transform.position; landingRay.direction = FPCamera.transform.forward; Debug.DrawRay(FPCamera.transform.position, FPCamera.transform.forward * InteractionDistance); //STRZELANIE RAYCASTEM if (Physics.Raycast(landingRay, out hit, InteractionDistance)) { if (hit.collider.GetComponent <_gripable>()) { GuiMessage = "Grab gripable " + hit.collider.name.ToString(); if (Input.GetKey(KeyCode.F) && !CurrentItemPosition.GetComponent <SpringJoint>()) { if (hit.collider.tag == "NPC") { hit.collider.gameObject.GetComponent <npcMove>().DestroyNavMesh(); } SpringJoint Joint = CurrentItemPosition.AddComponent(typeof(SpringJoint)) as SpringJoint; Joint.anchor = new Vector3(0, 0, 0); Joint.autoConfigureConnectedAnchor = false; Joint.connectedAnchor = new Vector3(0, 0, 0); Joint.minDistance = 0.0f; Joint.maxDistance = 0.1f; Joint.spring = 200; Joint.damper = 0; Joint.connectedBody = hit.rigidbody; hit.rigidbody.drag = 4; Joint.enableCollision = true; } } //ŁAPANIE ITEMOW else if ((hit.collider.GetComponent <Gun>() || hit.collider.GetComponent <GunAmmo>())) { if (hit.collider.GetComponent <Gun>() && hit.collider.GetComponent <Gun>().Type != GunType.meelee) { GuiMessage = "Grab gun" + hit.collider.GetComponent <Gun>().Type; } if (Input.GetKeyDown(KeyCode.F)) { character.ItemsList.Add(hit.collider.gameObject); //Wez do tej listy cały gameobject hit.collider.gameObject.GetComponent <Rigidbody>().isKinematic = true; hit.collider.gameObject.GetComponent <Rigidbody>().useGravity = false; if (hit.collider.GetComponent <Gun>()) { Debug.Log("Podniesiono " + hit.collider.GetComponent <Gun>().Type + " health:" + hit.collider.GetComponent <Gun>().Health + " ammo: " + hit.collider.GetComponent <Gun>().AmmoLoaded); } else if (hit.collider.GetComponent <GunAmmo>()) { Debug.Log("Podniesiono " + hit.collider.GetComponent <GunAmmo>().ammoType + " ammo: " + hit.collider.GetComponent <GunAmmo>().ammoAmount); } hit.collider.gameObject.transform.position = BackItemPosition.transform.position; hit.collider.gameObject.transform.rotation = BackItemPosition.transform.rotation; hit.collider.gameObject.transform.SetParent(BackItemPosition.transform); AudioSourceHandlerScript.PlayAudio(GunPickUpAudioClip, transform.position, 1.0f); } } } else { GuiMessage = ""; } if (Input.GetKeyUp(KeyCode.F) && CurrentItemPosition.GetComponent <SpringJoint>()) { CurrentItemPosition.GetComponent <SpringJoint>().connectedBody.GetComponent <Rigidbody>().drag = 0.2f; Destroy(CurrentItemPosition.GetComponent <SpringJoint>()); } }