/// <summary> /// Search for colliders in front of player, if player or breakable object attempt to deal damage to them /// Should be called as animation event /// </summary> public void TryDealDamage() { Collider[] hitColliders = Physics.OverlapSphere(transform.position + transform.forward, 0.8f); foreach (Collider col in hitColliders) { //check if enemy/ breakable object //deal dmaamge if (col.CompareTag("Enemy")) { EnemyController enemy = col.GetComponent <EnemyController>(); if (enemy) { enemy.ModifyHealth(damageDealt); } } else if (col.CompareTag("Breakable")) { BreakableObject breakable = col.GetComponent <BreakableObject>(); if (breakable) { breakable.ModifyHealth(damageDealt); } } } }
void Awake() { rigidBody = GetComponent <Rigidbody>(); healthController = new HealthController(health); breakableObject = GetComponent <BreakableObject>(); isBreakable = breakableObject != null; }
IEnumerator Shoot() { shootEfect.Play(); shootGunSound.Play(); RaycastHit hit; if (Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out hit, range)) { BreakableObject breakableObject = hit.transform.GetComponent <BreakableObject>(); Bomb bombObj = hit.transform.GetComponent <Bomb>(); if (breakableObject != null) { glassBrokeSound.Play(); breakableObject.triggerBreak(); gameContoller.AddScore(); } else if (bombObj != null) { explosionSound.Play(); bombObj.triggerBreak(); bloodCanvas.SetActive(true); yield return(new WaitForSeconds(1)); gameContoller.EndLevel(true); } } }
/// <summary> /// 攻击可破碎对象 /// </summary> /// <param name="attacker"></param> public override void BreakBreakableObjects(Agent attacker) { if (attacker.IsPlayer == false) { return; } BreakableObject breakObj = null; Vector3 dir; for (int i = 0; i < BreakableObjects.Length; i++) { breakObj = BreakableObjects [i]; if (breakObj.IsActive == false || breakObj.enabled == false) { continue; } dir = breakObj.Position - attacker.Position; //todo: 玩家攻击范围外就不能破碎物品 if (dir.sqrMagnitude > 10) { continue; } breakObj.Break(); } }
public override void BreakBreakableObjects(Agent attacker) { if (attacker.IsPlayer == false) { return; } BreakableObject bo = null; Vector3 dir; for (int i = 0; i < BreakableObjects.Length; i++) { bo = BreakableObjects[i]; if (bo.IsActive == false || bo.enabled == false) { continue; } dir = bo.Position - attacker.Position; if (dir.sqrMagnitude > attacker.BlackBoard.sqrWeaponRange) { continue; } bo.Break(); } }
void Start() { go = gameObject; if (go != null) { if (go.GetComponent <PlayerController>()) //<<------ if this object is the player { pHealthSystem = go.GetComponent <PlayerHealthSystem>(); } else if (go.GetComponent <EnemyHandleInteract>()) //<<------------ if this object is an enemy { eHandleInteract = go.GetComponent <EnemyHandleInteract>(); } else if (go.GetComponent <BreakableObject>()) //<<------- if this object is a breakable object { bO = go.GetComponent <BreakableObject>(); } else if (go.GetComponent <RollingObject>()) //<<--------- if this object is a rolling object { rO = go.GetComponent <RollingObject>(); } } else { Debug.LogError("No game object assigned to slot!"); } }
public static PacketWriter Interact(BreakableObject breakable) { PacketWriter pWriter = PacketWriter.Of(SendOp.Breakable); pWriter.Write(BreakablePacketMode.Interact); WriteBreakable(pWriter, breakable); return(pWriter); }
public SpawnedVase(GameObject o, GameObject s) { vaseObject = o; vaseStand = s; loudObject = Utils.GetRequiredComponentInChildren <LoudObject>(vaseObject); breakableObject = Utils.GetRequiredComponentInChildren <BreakableObject>(vaseObject); }
void Awake() { myNav = GetComponent <NavMeshAgent>(); myObjectBreaker = GetComponent <BreakableObject>(); playersPlaying = FindObjectOfType <Players>(); mySource = GetComponent <AudioSource>(); myHealth = GetComponent <RobotCenterHealth>(); }
private static void WriteBreakable(PacketWriter pWriter, BreakableObject breakable) { pWriter.WriteString(breakable.Id); pWriter.Write(breakable.State); pWriter.WriteBool(breakable.IsEnabled); pWriter.WriteInt(); pWriter.WriteInt(); // looks to be some server tick stamp? }
void Start() { hp = this.GetComponent <BreakableObject>(); bAttacks = this.GetComponent <BossAttacks>(); SetStats(); //wouter StartMusic MusicGameplayNonLineair.start(); }
private void OnTriggerEnter(Collider other) { if (!sentinel) { sentinel = true; if (other.CompareTag("Breakable")) { BreakableObject breakable = other.transform.parent.GetComponent <BreakableObject>(); if (!breakable.isBroken) { AudioManager.GetComponent <AudioSource>().PlayOneShot(AudioManager.GetComponent <AudioLoader>().GetBreakingSound(), 0.5f); // plays random breaking sound CameraShaker.Instance.camera = camera; CameraShaker.Instance.ShakeOnce(4f, 4f, 0.1f, .3f); if (isReturning) { score.AddScore(-1); } else { score.AddScore(1); } } else if (breakable.isBroken && isReturning) { AudioManager.GetComponent <AudioSource>().PlayOneShot(AudioManager.GetComponent <AudioLoader>().GetFixingSound(), 0.5f); // plays random fixing sound score.AddScore(1); } breakable.SwitchState(); } else if (other.CompareTag("CutSceneRoom")) { isReturning = true; mode = GameMode.CutScene; //if (orientation == Orientation.Left) orientation = Orientation.Right; //else if (orientation == Orientation.Right) orientation = Orientation.Left; //Vector3 position = transform.position; //if (playerType == PlayerType.PlayerOne) position.x = 5; //else position.x = 0; //transform.position = position; } else if (other.CompareTag("EndWall")) { mode = GameMode.GameOver; //gameOver = true; } else if (other.CompareTag("Trap")) { score.AddScore(-1); } } }
/// <summary> /// Finaliza la ejecución de la habilidad de romper /// </summary> /// <returns><c>true</c> si se pudo parar la ejecución, <c>false</c> si no fue posible.</returns> public override bool DeactivateAbility() { bool res = (active && breakPoint); if (res) { // Termina ejecución y bloquea al jugador para evitar que se mueva durante la animación active = false; objectToBreak = null; breakPoint = false; CallEventDeactivateAbility(); } return res; }
public override bool SetReady(bool r, GameObject go = null, RaycastHit hitInfo = default(RaycastHit)) { if ((r) && (hitInfo.collider.tag.Equals("Breakable"))) { // La habilidad está lista para ser usada ready = true; objectToBreak = hitInfo.collider.GetComponent<BreakableObject>(); objectToBreak.SetBreakPoint(hitInfo.point); } else { ready = false; } return ready; }
private SpawnedVase SpawnVase(Vector3 position, bool trackBrokenVase = true) { GameObject vaseInstance = Instantiate(vasePrefab, position, Quaternion.identity); GameObject vaseStandInstance = Instantiate(vaseStandPrefab, new Vector3(position.x - 0.8f, 0f, position.z - 1f), Quaternion.identity); if (trackBrokenVase) { BreakableObject breakableVase = Utils.GetRequiredComponentInChildren <BreakableObject>(vaseInstance); breakableVase.OnBreak += OnVaseBreak; } return(new SpawnedVase(vaseInstance, vaseStandInstance)); }
private void OnTriggerStay(Collider other) { if (other.gameObject.CompareTag(Tags.repairObjectTag)) { if (Input.GetButtonDown("Fire1")) { BreakableObject breakableObject = other.GetComponent <BreakableObject>(); breakableObject.InReparation(); Invoke("EnableMovement", breakableObject.reparationTime); AudioManager.instance.PlayAudio(AudioManager.instance.playerAudio, AudioKey.Repair); UIManager.instance.TriggerRepairProgress(); fsm = FSM.Repairing; } } }
public Issue CreateIssue(BreakableObject relatedObject) { Issue newIssue = new Issue(WordGen.generateWord(), relatedObject); OnIssueCreatetd(newIssue, AllRepairComponentPrefaps); if (currentIssueList.ContainsKey(relatedObject)) { currentIssueList[relatedObject] = newIssue; } else { currentIssueList.Add(relatedObject, newIssue); } WordGen.generateWord(); return(newIssue); }
void OnCollisionEnter2D(Collision2D collision) { GameObject obj = collision.collider.gameObject; if (obj) { Damageable objDMG = obj.GetComponent <Damageable>(); Rigidbody2D objRB = obj.GetComponent <Rigidbody2D>(); if (objDMG && objRB) { float acceleration = (objRB.velocity - objDMG.lastVelocity).magnitude / Time.fixedDeltaTime; BreakableObject br = obj.GetComponent <BreakableObject>(); if (br) { if (br.GetArea() < 5f) { return; } else { Rigidbody2D rb = GetComponent <Rigidbody2D>(); if (rb) { Vector3 impactPoint = transform.position - collision.collider.transform.position; Vector3 finalPoint = impactPoint + (Vector3)rb.velocity; br.Adjust(impactPoint, finalPoint, acceleration * objRB.mass); } } } float damage = acceleration / objRB.mass * damageFactor; if (damage >= 1f) { //Debug.Log(name + " damaged " + objDMG.name + " by " + damage); objDMG.Damage(damage); } } } }
private void BreakCleanableObject(bool withTimer) { List <BreakableObject> availableBreakableObjects = new List <BreakableObject>(); for (int i = 0; i < cleanableObjects.Count; i++) { if (cleanableObjects[i].GetType() == typeof(BreakableObject)) { BreakableObject breakableObject = (BreakableObject)cleanableObjects[i]; if (!breakableObject.IsBroken) { availableBreakableObjects.Add(breakableObject); } } } if (availableBreakableObjects.Count > 0) { availableBreakableObjects[UnityEngine.Random.Range(0, availableBreakableObjects.Count)].Set_ObjectStateToDirty(); } }
public void GenerateAsteroid(bool removeAfter = true) { if (sides < 3) { sides = 3; } Vector3[] vertices = GenerateVertices(GenerateAngles()); GetComponent <MeshFilter>().mesh = GenerateMesh(vertices); GetComponent <PolygonCollider2D>().points = Array.ConvertAll(vertices, v => (Vector2)v).ToArray(); BreakableObject bo = GetComponent <BreakableObject>(); if (bo) { float thickness = GetComponent <MeshRenderer>().material.GetFloat("_OutlineThickness") / Mathf.Clamp(Mathf.Sqrt(bo.GetArea() * 0.25f), 1f, 100f); GetComponent <MeshRenderer>().material.SetFloat("_OutlineThickness", thickness); } if (removeAfter) { Destroy(this); } }
private void SubscribeToScore(BreakableObject obj) { obj.ObjectRepaired += AddScore; }
private void Instance_OnIssueFixed(Issue Issue, BreakableObject arg1) { Destroy(issuesOnTheList[Issue].gameObject); FixedTextAnimation(Issue); }
private void CheckSurroundings() { // ---- CHECK FOR GROUND RaycastHit2D onGround = Physics2D.Raycast(onGroundCheck.position, Vector2.down, groundCheckDistance, groundLayerMask); Debug.DrawRay(onGroundCheck.position, Vector2.down * groundCheckDistance, Color.red); RaycastHit2D toeHitGround = Physics2D.Raycast(toeGroundCheck.position, Vector2.down, groundCheckDistance, groundLayerMask); Debug.DrawRay(toeGroundCheck.position, Vector2.down * groundCheckDistance, Color.yellow); RaycastHit2D heelHitGround = Physics2D.Raycast(heelGroundCheck.position, Vector2.down, groundCheckDistance, groundLayerMask); Debug.DrawRay(heelGroundCheck.position, Vector2.down * groundCheckDistance, Color.yellow); if (onGround.collider != null) { isOnGround = true; int currentLayer = onGround.collider.gameObject.layer; if (currentLayer == breakableObjectsLayer) { BreakableObject bo = onGround.collider.gameObject.GetComponent <BreakableObject>(); if (bo == null) { Debug.LogError("Object on Breakable Objects layer does not have Breakable Object component!"); } else if (bo.isPlatform && !bo.isFallingApart) { bo.TriggerPlatformCollapse(); } } else if (currentLayer == breakableFloorsLayer) { BreakableFloor bf = onGround.collider.gameObject.GetComponent <BreakableFloor>(); if (bf == null) { Debug.LogError("Object on Breakable Floors layer does not have Breakable Floors component!"); } else if (inAir) { bf.TriggerObjectShake(); } } else if (currentLayer == slidingSurfaceLayer && !isPressingJumpButton && !magBootsOn) { SlidingSurface ss = onGround.collider.gameObject.GetComponent <SlidingSurface>(); if (ss == null) { Debug.LogError("Object on Sliding Surface layer does not have Sliding Surface component!"); } else { SlopeSlide(ss.direction); } } else if (currentLayer != slidingSurfaceLayer && isGroundSliding || isGroundSliding && magBootsOn) { print("Stop"); StopSlopeSlide(); } } else if (onGround.collider == null && isGroundSliding) { if (direction == Vector2.right) { move.x = 16; } else { move.x = -16; } targetVelocity.x = move.x; } else if (onGround.collider == null) { if (toeHitGround.collider != null && heelHitGround.collider == null && !hasJumped) { move.x = -3f; } else if (toeHitGround.collider == null && heelHitGround.collider != null && !hasJumped) { move.x = 3f; } else if (toeHitGround.collider == null && heelHitGround.collider == null) { isOnGround = false; } } // ---- CHECK FOR WALLS if (canMove && !isDisabled) { ContactFilter2D contactFilter = new ContactFilter2D(); contactFilter.SetLayerMask(wallLayerMask); RaycastHit2D[] hit = new RaycastHit2D[1]; isTouchingWall = Physics2D.Raycast(wallCheck.position, direction, contactFilter, hit, wallCheckDistance) > 0; Debug.DrawRay(wallCheck.position, direction * wallCheckDistance, Color.red); isTouchingLedge = Physics2D.Raycast(ledgeCheck.position, direction, ledgeCheckDistance, wallLayerMask); Debug.DrawRay(ledgeCheck.position, direction * ledgeCheckDistance, Color.red); // Check for ledge grab if (isTouchingWall && !isTouchingLedge && !ledgeDetected)// << ----------- OPTION TO PUT MANUAL LEDGE GRAB HERE { ledgeDetected = true; // playerposition = hitpointx - wallcheck transform.position = new Vector3(hit[0].point.x + (direction == Vector2.right ? wallCheckDistance : -wallCheckDistance), transform.position.y, transform.position.z); ledgePosBot = wallCheck.position; } // Check for crumbling wall if (isWallSliding) { RaycastHit2D hitWall = Physics2D.Raycast(wallCheck.position, direction, wallCheckDistance, groundLayerMask); if (hitWall.collider != null) { int currentLayer = hitWall.collider.gameObject.layer; if (currentLayer == breakableObjectsLayer) { BreakableObject crumblingWall = hitWall.collider.gameObject.GetComponent <BreakableObject>(); if (crumblingWall != null) { print("hit crumbling wall"); crumblingWall.TriggerPlatformCollapse(); StopWallSliding(); } else { Debug.LogError("Object on Breakable Object layer does not have Breakable Object component!"); } } } } } }
// < ------------------------------------- TRACK BREAKABLE WALLS ----------------------------- >> // public void AddBreakableObjects(BreakableObject _breakableObject) { breakableObjects.Add(_breakableObject); }
private void Start() { bo = GetComponent <BreakableObject>(); }
void Break(int index) { // to create breaking effect, instantiate a broken version of model at the same place and with same rotation if (GetComponent <Egg>()) { // half cracked egg -> full cracked egg if (GetComponent <BreakableObject>().breakingThresholds.Length == 1) { Instantiate(GetComponent <Egg>().insideEggPrefab, transform.position, GetComponent <Egg>().insideEggPrefab.transform.rotation); brokenObject = Instantiate(brokenModelPrefabs[index], transform.position + new Vector3(0, 0.1f, 0), brokenModelPrefabs[index].transform.rotation); } else { // egg -> full cracked egg if (index == 1) { Instantiate(GetComponent <Egg>().insideEggPrefab, transform.position, GetComponent <Egg>().insideEggPrefab.transform.rotation); brokenObject = Instantiate(brokenModelPrefabs[index], transform.position + new Vector3(0, 0.1f, 0), brokenModelPrefabs[index].transform.rotation); } // egg -> half cracked egg else { brokenObject = Instantiate(brokenModelPrefabs[index], transform.position, brokenModelPrefabs[index].transform.rotation); brokenObject.AddComponent <PullFromBothSides_GrabAction>().ungrabDistance = 0.2f; BreakableObject breakableObject = brokenObject.AddComponent <BreakableObject>(); breakableObject.brokenModelPrefabs = new GameObject[1]; breakableObject.brokenModelPrefabs[0] = brokenModelPrefabs[1]; breakableObject.breakingThresholds = new float[1]; breakableObject.breakingThresholds[0] = (breakingThresholds[1] + breakingThresholds[0]) / 2; breakableObject.breakSounds = new AudioClip[1]; breakableObject.breakSounds[0] = breakSounds[1]; Egg crackedEgg = brokenObject.AddComponent <Egg>(); crackedEgg.insideEggPrefab = GetComponent <Egg>().insideEggPrefab; crackedEgg.isCracked = true; } } } else { brokenObject = Instantiate(brokenModelPrefabs[index], transform.position, brokenModelPrefabs[index].transform.rotation); } int fragmentCount = brokenObject.transform.childCount; foreach (Transform child in brokenObject.transform) { if (brokenObject.GetComponent <Egg>() && brokenObject.GetComponent <Egg>().isCracked) { break; } if (child.gameObject.GetComponent <MeshFilter>()) { if (child.gameObject.GetComponent <MeshFilter>().sharedMesh.vertexCount > 255) { BoxCollider collider = child.gameObject.AddComponent <BoxCollider>(); } else { MeshCollider collider = child.gameObject.AddComponent <MeshCollider>(); collider.cookingOptions = MeshColliderCookingOptions.InflateConvexMesh | MeshColliderCookingOptions.CookForFasterSimulation | MeshColliderCookingOptions.WeldColocatedVertices | MeshColliderCookingOptions.EnableMeshCleaning; collider.skinWidth = 0.001f; collider.convex = true; } } Rigidbody childRigidbody = child.gameObject.AddComponent <Rigidbody>(); if (childRigidbody) { // give a realistic weight to fragments equally. childRigidbody.mass = GetComponent <Rigidbody>().mass / fragmentCount * 6; // apply physics childRigidbody.useGravity = true; childRigidbody.isKinematic = false; // after breaking, fragments are exposed forces and therefore they are kind of slipping // to get rid of this effect, set velocity of fragment 0. childRigidbody.velocity = Vector3.zero; childRigidbody.angularVelocity = Vector3.zero; } } // remove the original object Destroy(gameObject); // play breaking sound AudioSource.PlayClipAtPoint(breakSounds[index], transform.position); isBroken = true; }
// Use this for initialization void Start() { AbilityInitialization(); objectToBreak = null; breakPoint = false; abilityName = AbilityName.Break; }
public void Register(BreakableObject breakableObject) { breakableObjects.Add(breakableObject); }
public override void SetCorredor() { if (GameManager.instance.rpgTalk.isPlaying) { GameManager.instance.rpgTalk.EndTalk(); } if (GameManager.previousSceneName.Equals("GameOver") && Cat.instance == null) { // Gato GameObject cat = GameManager.instance.AddObject( "NPCs/catFollower", "", new Vector3(player.transform.position.x + 0.6f, player.transform.position.y, 0), new Vector3(0.15f, 0.15f, 1)); cat.GetComponent <Cat>().FollowPlayer(); } if (Crow.instance != null) { Crow.instance.DestroyRaven(); } GameManager.instance.scenerySounds.StopSound(); // LUZ DO AMBIENTE mainLight.transform.Rotate(new Vector3(50, mainLight.transform.rotation.y, mainLight.transform.rotation.z)); if (GameManager.instance.invertWorld) { invertLocal = true; mainLight.transform.Rotate(new Vector3(-40, mainLight.transform.rotation.y, mainLight.transform.rotation.z)); if (Cat.instance) { Cat.instance.GetComponent <SpriteRenderer>().color = Color.black; } } if (secao == enumMission.GATO_ACELERA || secao == enumMission.GATO_CORREDOR) { EspecificaEnum((int)enumMission.GATO_CORREDOR); } else if ((secao == enumMission.ARMARIO)) { EspecificaEnum((int)enumMission.GRANDE_BARULHO); } vaso = GameObject.Find("VasoNaoEmpurravel").gameObject; breakVaso = vaso.GetComponent <BreakableObject>(); vasoDefaultY = vaso.transform.position.y; vasoDefaultX = vaso.transform.position.x; if (secao >= enumMission.VASO_GATO) { vaso.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Sprites/Objects/Scene/vasoPlanta_quebrado"); } else if (secao == enumMission.GRANDE_BARULHO) { vaso.GetComponent <RegularObject>().enabled = false; vaso.GetComponent <BreakableObject>().enabled = true; } if (secao == enumMission.VASO_GATO) { GameManager.instance.AddObject( "NPCs/catFollower", "", new Vector3(-7f, -0.6f, 0), new Vector3(0.15f, 0.15f, 1)); } if ((secao == enumMission.FRENTE_CRIADO || secao == enumMission.MI_ATIVADO || secao == enumMission.MI_DESATIVADO) && GameManager.previousSceneName.Equals("Sala")) { GameManager.instance.rpgTalk.NewTalk("M4DicaCorredor", "M4DicaCorredorEnd", GameManager.instance.rpgTalk.txtToParse); } if (secao >= enumMission.QUEBRADO && secao < enumMission.MAE_CHEGA_CORREDOR) { SetMae(); } else if (!GameManager.instance.invertWorld) { // PortaMãe GameObject portaMae = GameObject.Find("DoorToMomRoom").gameObject; portaMaeDefaultY = portaMae.transform.position.y; portaMaeDefaultX = portaMae.transform.position.x; float posX = portaMae.GetComponent <SpriteRenderer>().bounds.size.x / 5; portaMae.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Sprites/Objects/Scene/door-closed"); portaMae.GetComponent <SceneDoor>().isOpened = false; portaMae.transform.position = new Vector3(portaMae.transform.position.x + posX, portaMaeDefaultY, portaMae.transform.position.z); } if (secao == enumMission.MAE_CHEGA_CORREDOR) { GameManager.instance.AddObject("NPCs/mom", "", new Vector3(-3f, -0.5f, -0.5f), new Vector3(0.3f, 0.3f, 1)); GameObject trigger3 = GameManager.instance.AddObject("Scenery/AreaTrigger", "", new Vector3(-2f, 0f, 1), new Vector3(1, 1, 1)); trigger3.name = "MaeTrigger2"; trigger3.GetComponent <Collider2D>().offset = new Vector2(0, 0); trigger3.GetComponent <BoxCollider2D>().size = new Vector2(2f, 2f); } }
internal void IssueFixed(BreakableObject breakableObject) { OnIssueFixed(currentIssueList[breakableObject], breakableObject); currentIssueList.Remove(breakableObject); }
public Issue(SerchedComponentenWort seekedWords, BreakableObject relatedObject) { this.relatedObject = relatedObject; this.seekedWord = seekedWords; }
public ObjectEvent(BreakableObject obj) { mObject = obj; }