private void ExplodeObject(GameObject gameObject) { ExploderUtils.SetActive(Exploder.gameObject, true); Exploder.transform.position = ExploderUtils.GetCentroid(gameObject); Exploder.Radius = 1.0f; Exploder.ExplodeRadius(); }
private void OnGUI() { if (GUI.Button(new Rect(10, 10, 100, 30), "Explode!")) { if (Exploder) { Exploder.ExplodeRadius(); } } if (GUI.Button(new Rect(130, 10, 100, 30), "Reset")) { // activate exploder ExploderUtils.SetActive(Exploder.gameObject, true); if (!Exploder.DestroyOriginalObject) { foreach (var destroyableObject in DestroyableObjects) { ExploderUtils.SetActiveRecursively(destroyableObject, true); } ExploderUtils.SetActive(Exploder.gameObject, true); } } }
public void Explode() { if (explosionInProgress) { return; } explosionInProgress = true; throwing = false; if (!Impact) { // grenade is still in the air explodeTimeoutMax = 5.0f; } else { exploder.transform.position = transform.position; // dont destroy exploder game object exploder.ExplodeSelf = false; // dont use force vector, default is explosion in every direction exploder.UseForceVector = false; // set explosion radius to 5 meters exploder.Radius = 5.0f; // fragment pieces exploder.TargetFragments = 200; // adjust force exploder.Force = 20; // run explosion exploder.ExplodeRadius(OnExplode); ExploderUtils.Log("Explode(OnExplode)"); ExplodeFinished = false; } }
public override void Use() { base.Use(); Exploder.transform.position = ChairBomb.transform.position; // dont destroy exploder game object Exploder.ExplodeSelf = false; // dont use force vector, default is explosion in every direction Exploder.UseForceVector = false; // set explosion radius to 5 meters Exploder.Radius = 10.0f; // fragment pieces Exploder.TargetFragments = 300; // adjust force Exploder.Force = 30; // run explosion Exploder.ExplodeRadius(OnExplode); }
private void OnRocketHit(Vector3 position) { nextShotTimeout = 0.6f; // place the exploder object to centroid position exploder.transform.position = position; exploder.ExplodeSelf = false; exploder.Force = 20; // fragment pieces exploder.TargetFragments = 100; // set explosion radius to 10 meters exploder.Radius = 10.0f; exploder.UseForceVector = false; // run explosion exploder.ExplodeRadius(); // reset rocket position Rocket.Reset(); }
private void Update() { GameObject hitObject = null; var targetType = TargetManager.Instance.TargetType; // dont shoot when targeting use object if (targetType == TargetType.UseObject) { if (lastTarget != TargetType.UseObject) { // animation["shotgunHide"].speed = 1; // animation.Play("shotgunHide"); } lastTarget = TargetType.UseObject; } if (lastTarget == TargetType.UseObject) { // animation["shotgunHide"].speed = -1; // // if (animation["shotgunHide"].time < 0.01f) // { // animation["shotgunHide"].time = animation["shotgunHide"].length; // } // // animation.Play("shotgunHide", AnimationPlayMode.Mix); } lastTarget = targetType; // run raycast against objects in the scene var mouseRay = MouseLookCamera.mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f)); UnityEngine.Debug.DrawRay(mouseRay.origin, mouseRay.direction * 10, Color.red, 0); if (targetType == TargetType.DestroyableObject) { hitObject = TargetManager.Instance.TargetObject; } if (Input.GetMouseButtonDown(0) && nextShotTimeout < 0 && CursorLocking.IsLocked) { if (targetType != TargetType.UseObject) { Source.PlayOneShot(GunShot); MouseLookCamera.Kick(); // play reload sound after this timeout reloadTimeout = 0.3f; // turn on flash light for 5 frames flashing = 5; } if (hitObject) { // get centroid of the hitting object var centroid = ExploderUtils.GetCentroid(hitObject); // place the exploder object to centroid position exploder.transform.position = centroid; exploder.ExplodeSelf = false; // adjust force vector to be in direction from shotgun exploder.ForceVector = mouseRay.direction.normalized; // Utils.Log("ForceVec: " + exploder.ForceVector); exploder.Force = 10; exploder.UseForceVector = true; // fragment pieces exploder.TargetFragments = 30; // set explosion radius to 5 meters exploder.Radius = 1.0f; // run explosion exploder.ExplodeRadius(); } nextShotTimeout = 0.6f; } nextShotTimeout -= Time.deltaTime; if (flashing > 0) { Flash.intensity = 1.0f; ExploderUtils.SetActive(MuzzleFlash, true); flashing--; } else { Flash.intensity = 0.0f; ExploderUtils.SetActive(MuzzleFlash, false); } reloadTimeout -= Time.deltaTime; if (reloadTimeout < 0.0f) { reloadTimeout = float.MaxValue; // play reload sound Source.PlayOneShot(Reload); // play reload animation ReloadAnim.Play(); } }