// Use this for initialization void Start() { brk = GetComponent<Breakable>(); fullHealth = brk.initialHealth; sr = GetComponent<SpriteRenderer>(); UpdateDisplay (fullHealth); }
void Start() { this.defaultPosition = transform.position; this.defaultRotation = transform.rotation; //// Determine if this is a root object // Get the parent GameObject parent = transform.parent.gameObject; // If parent exist, get the Breakable module if (parent != null) { Breakable parentBreakable = parent.GetComponent <Breakable>(); // If the module exists, set the root to false this.defaultRoot = parentBreakable == null; } this.root = this.defaultRoot; //// Actions // On child destroy this.onChildDestroy = (Breakable br) => { this.destroyedChildren += 1; // All the children have been destroyed. This means // that this node can be destroyed as well if (this.destroyedChildren == this.children.Count) { this.onDestroy(this); this.destroyedChildren = 0; } }; }
private void Start() { Breakable[] breakables = FindObjectsOfType <Breakable>(); m_Arrows = new Arrow[breakables.Length]; for (int i = 0; i < breakables.Length; i++) { Breakable b = breakables[i]; Arrow arrow = new Arrow(); if (b.IsCritical()) { arrow.arrow = Instantiate(m_BigArrowPrefab, transform); } else { arrow.arrow = Instantiate(m_SmallArrowPrefab, transform); } arrow.arrowImage = arrow.arrow.GetComponent <Image>(); arrow.target = b.gameObject; b.m_OnBreak.AddListener(() => { arrow.arrow.SetActive(true); }); b.m_OnFix.AddListener(() => { arrow.arrow.SetActive(false); }); arrow.arrow.SetActive(false); m_Arrows[i] = arrow; } }
public void StopFixing() { this.breakable = null; this.isFixing = false; this.actualFixingTime = 0.0f; this.totalFixingTime = 1.0f; }
void OnCollisionEnter2D(Collision2D other) { rigidbody2d.simulated = false; transform.position = other.transform.position; animator.Play("BulletImpact"); if (other.gameObject.CompareTag("NotDestructible")) { Destroy(gameObject); } else { if (other.gameObject.CompareTag("Destructible")) { Breakable b = other.gameObject.GetComponent <Breakable>(); b.takeDamage(1); } if (other.gameObject.CompareTag("Enemy")) { EnemyScript b = other.gameObject.GetComponent <EnemyScript>(); b.takeDamage(1, currentDir); } } }
// Use this for initialization void Start() { brk = GetComponent <Breakable>(); fullHealth = brk.initialHealth; sr = GetComponent <SpriteRenderer>(); UpdateDisplay(fullHealth); }
//CALLBACKS void onNodeBroken(Breakable node) { foreach (NetworkInterface netInt in interfaces.Values) { netInt.Clear(); } }
private void OnCollisionEnter(Collision col) { if (projectileType == ProjectileType.Instant) { if (collisionLayers == (collisionLayers | (1 << col.gameObject.layer))) { Rigidbody colRigid = col.gameObject.GetComponent <Rigidbody>(); if (colRigid) { colRigid.AddForce(transform.forward * GetComponent <Rigidbody>().velocity.magnitude); } Breakable hitBreakable = col.gameObject.GetComponent <Breakable>(); if (hitBreakable) { hitBreakable.Impact(col.contacts[0].normal, damage); } ActivateProjectile(col, col.contacts[0].normal); } } if (projectileType == ProjectileType.Timed) { if (col.gameObject.layer == 12) //Ai { Rigidbody colRigid = col.gameObject.GetComponent <Rigidbody>(); if (colRigid) { colRigid.AddForce(transform.forward * GetComponent <Rigidbody>().velocity.magnitude); } ActivateProjectile(col, col.contacts[0].normal); } } }
// Update is called once per frame void Update() { if (br == null) { fire.SetActive(true); RaycastHit hit; if (Physics.Raycast(fire.transform.position, fire.transform.forward, out hit, 1.5f)) { //Debug.DrawLine (fire.transform.position,fire.transform.position + (-fire.transform.up * 1.5f)); Fracture fract = hit.collider.gameObject.GetComponent <Fracture> (); Breakable breaka = hit.collider.gameObject.GetComponent <Breakable> (); if (fract != null) { fract.Break(0); } else if (breaka != null) { breaka.Break(0); } } } if (!dm.beingHeld && br == null) { rb.AddExplosionForce(18f, fire.transform.position, 2f); } }
public void Fix(Breakable breakable) { this.breakable = breakable; this.isFixing = true; this.actualFixingTime = 0.0f; this.totalFixingTime = breakable.timeToFix; }
public void CreateText(Breakable obstacle, bool notVisible) { GameObject go = new GameObject(obstacle.name + " Text"); go.transform.SetParent(this.transform); go.AddComponent(typeof(Text)); go.GetComponent <Text>().text = obstacle.GetBreakCount().ToString(); go.GetComponent <Text>().font = font; go.GetComponent <Text>().fontSize = 50; go.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; go.GetComponent <Text>().fontStyle = FontStyle.Bold; go.GetComponent <RectTransform>().localScale = Vector3.one; go.transform.rotation = obstacle.gameObject.transform.rotation; go.AddComponent(typeof(Canvas)); go.GetComponent <Canvas>().overrideSorting = true; go.GetComponent <Canvas>().sortingLayerName = "Text"; if (notVisible) { go.transform.localScale = Vector3.zero; } breakables.Add(obstacle); texts.Add(go); }
protected override void HandleDamage(Collider2D other) { GameObject hit = other.gameObject; Health health = hit.GetComponent <Health>(); Breakable breakHealth = hit.GetComponent <Breakable>(); if (health != null) { health.Damage(damage); health.lastHit = playerIndex; Destroy(gameObject); } else if (breakHealth != null) { breakHealth.Damage(damage); Destroy(gameObject); } this.GetComponent <Collider2D>().isTrigger = false; source.Play(); numOfBounces++; if (numOfBounces >= maxNumOfBounces) { Destroy(gameObject); } }
/** * Projectiles will expire when they hit a wall, enemy, * or a breakable object. */ public virtual void OnCollisionEnter2D(Collision2D collision) { LivingEntity e = collision.gameObject.GetComponent <LivingEntity>(); Breakable b = collision.gameObject.GetComponent <Breakable>(); if (collision.gameObject.CompareTag("Wall")) { EndLife(); } else if (e != null && (alignment == Alignment.NEUTRAL || e.alignment != alignment)) { Damage(e); EndLife(); } else if (b != null) { b.TakeHit(damage, hitstun); EndLife(); } else if (collision.gameObject.CompareTag("Water")) { Physics2D.IgnoreCollision(GetComponent <Collider2D>(), collision.gameObject.GetComponent <Collider2D>()); rb.freezeRotation = true; } }
void OnTriggerEnter2D(Collider2D collider) { if (collider.tag == "Player") { CharacterController2D player = collider.GetComponent <CharacterController2D> (); if (player.playerCanMove == true) { // attack sound //playSound(attackSFX); // apply damage to the player player.ApplyDamage(damageAmount); } } else { // can enemy destroy breakable objects? yes Breakable breakable = collider.GetComponent <Breakable> (); if (breakable != null) // destroy breakable objects { breakable.Break(); } } // destroy itself when hitting an object Destroy(gameObject); }
void OnTriggerEnter2D(Collider2D collider) { Enemy enemy = collider.GetComponent <Enemy> (); if (enemy != null) // collide with an enemy { if (collider.tag == "Boss") // for boss, call stunned to deal with damage { enemy.Stunned(); } else // for others just die { enemy.Die(); } } Breakable breakable = collider.GetComponent <Breakable>(); if (breakable != null) // destroy breakable objects { breakable.Break(); } Interactive interactive = collider.GetComponent <Interactive>(); if (interactive != null) // trigger interactive objects { interactive.Trigger(); } // destroy itself when hitting an object Destroy(gameObject); }
public void FindBreakable() { Navigator navigator = GetComponent <Navigator>(); int num = 2147483647; Breakable breakable = null; if (UnityEngine.Random.Range(0, 100) >= 50) { foreach (Breakable item in Components.Breakables.Items) { if (!((UnityEngine.Object)item == (UnityEngine.Object)null) && !item.isBroken()) { int navigationCost = navigator.GetNavigationCost(item); if (navigationCost != -1 && navigationCost < num) { num = navigationCost; breakable = item; } } } } if ((UnityEngine.Object)breakable == (UnityEngine.Object)null) { int value = GameUtil.FloodFillFind(delegate(int cell, object arg) { if (Grid.Solid[cell]) { return(false); } if (!navigator.CanReach(cell)) { return(false); } if (Grid.IsValidCell(Grid.CellLeft(cell)) && Grid.Solid[Grid.CellLeft(cell)]) { return(true); } if (Grid.IsValidCell(Grid.CellRight(cell)) && Grid.Solid[Grid.CellRight(cell)]) { return(true); } if (Grid.IsValidCell(Grid.OffsetCell(cell, 1, 1)) && Grid.Solid[Grid.OffsetCell(cell, 1, 1)]) { return(true); } if (Grid.IsValidCell(Grid.OffsetCell(cell, -1, 1)) && Grid.Solid[Grid.OffsetCell(cell, -1, 1)]) { return(true); } return(false); }, null, Grid.PosToCell(navigator.gameObject), 128, true, true); base.sm.moveToWallTarget.Set(value, base.smi); GoTo(base.sm.move_notarget); } else { base.sm.breakable.Set(breakable, base.smi); GoTo(base.sm.move_target); } }
public void PlayAudioFromBreaking(Breakable brokenObject) { //m_audioSource.clip = brokenObject.sound; //if (m_audioSource.clip) //{ // m_audioSource.Play(); //} }
// Use this for initialization void Start() { rb = GetComponent <Rigidbody> (); br = GetComponent <Breakable> (); dm = GetComponent <DebrisManager> (); fire = transform.Find("Fire").gameObject; fire.SetActive(false); }
public void Disable() { tank.gameObject.SetActive(false); path = null; pathUpdateTime = 0f; hasRequestedPath = false; targetBreakable = null; shootEnumerator = null; }
public void RemoveObstacle(Breakable obstacle) { int index = breakables.IndexOf(obstacle); Debug.Log(index); breakables.Remove(obstacle); Destroy(texts[index]); texts.RemoveAt(index); }
public void Grab() { // attempt to drag something Collider col = CheckInRange(grabLayer, ColliderIsDraggable); if (col != null) { // reset grab if (breakable != null) { breakable.BreakStop(); breakable = null; } // we are now dragging something Debug.Log("Grabbed: " + col.name); draggable = col.GetComponent <Draggable>(); joint.connectedBody = col.GetComponent <Rigidbody>(); if (!healthManager.isSweating) { healthManager.SweatToggle(); } return; } // attempt to pull something off if nothing to drag col = CheckInRange(breakLayer, ColliderIsBreakable); if (col != null) { // reset grab if (draggable != null) { draggable = null; joint.connectedBody = null; } if (breakable != null) { breakable.BreakStop(); } // we are now breaking something breakable = col.GetComponent <Breakable>(); breakable.BreakStart(transform.position); if (!healthManager.isSweating) { healthManager.SweatToggle(); } return; } Debug.Log("Grabbed: nothing :("); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Breakable") { GameObject breakObject = collision.gameObject; Breakable breakIt = breakObject.GetComponent <Breakable>(); breakIt.DestroyBreakable(); } }
public TankInstance(Tank tank) { this.tank = tank; path = null; pathUpdateTime = 0f; hasRequestedPath = false; targetBreakable = null; shootEnumerator = null; }
//Ataca a defense y le hace un daño equivalente a damage. protected void Attack(Breakable defense) { if (attackCountdown <= 0f) { defense.ToDamage(damage); attackCountdown = 1f / attackSpeed; } attackCountdown -= Time.deltaTime; }
/// <summary> /// this is call in the animation of hit in the correct time /// </summary> public void HitObject() { //We need to chechk if theres a brakable object in case its not the we avoid the error if (breakable != null) { breakable.Break(); breakable = null; } }
void breakBreakable(Breakable breakable, Vector3 position) { try { breakable.breakOut(position); } catch (Exception e) { print("error" + e); } }
private void RemoveLayer(RaycastHit2D hit, int damage) { Breakable breakable = hit.collider.gameObject.GetComponent <Breakable>(); if (breakable != null) { breakable.RemoveDurability(damage, _equippedTools); } }
void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Spell_Interactable") { SpellInteractable si = collision.gameObject.GetComponent <SpellInteractable>(); Breakable b = collision.gameObject.GetComponent <Breakable>(); if (si != null) { si.Trigger("magnosphere"); } if (b != null) { b.Break(); } Break(); } else if (collision.gameObject.tag == "Shield") { Shield s = collision.gameObject.GetComponent <Shield>(); if (s != null) { s.Break(); } Break(); } else if (collision.gameObject.tag == "Enemy") { EnemyAI enemy = collision.gameObject.GetComponent <EnemyAI>(); CasterAI caster = collision.gameObject.GetComponent <CasterAI>(); if (enemy != null) { enemy.TakeDamage(damageType, damage); } if (caster != null) { caster.TakeDamage(damageType, damage); } Break(); } else if (collision.gameObject.tag == "Player" && canHitPlayer) { Player player = collision.gameObject.GetComponent <Player>(); if (player != null) { player.WeaponHit(damage); } Break(); } Rigidbody r = collision.gameObject.GetComponent <Rigidbody>(); if (r != null) { r.AddExplosionForce(1500f, transform.position, 1f); } }
protected override void Startup() { breakable = GetComponent <Breakable>(); Broken.initialize(false); if (IsServer) { breakable.OnBreak.AddListener(OnBreakCallback); } Broken.OnReceiveNetworkValue = BrokenCallback; }
public override void FixedUpdate() { if (m_getBack) { Vector3 target = new Vector3(m_spawner.ProtestCenter + m_posFromCenter, 0, 0); Vector3 dir = (target - transform.position).normalized; transform.position += dir * m_breakSpeed * Time.fixedDeltaTime; if (Vector3.Distance(transform.position, target) < m_attackRange) { m_target = null; m_rigidbody.GetComponent <Collider>().enabled = true; m_getBack = false; } } else if (m_target == null) { base.FixedUpdate(); Collider[] breakables = Physics.OverlapBox(transform.position, new Vector3(m_visionRadius, 100, 100), Quaternion.identity, m_layerMask); if (breakables.Length > 0) { foreach (Collider collider in breakables) { Breakable breakable = collider.GetComponent <Breakable>(); if (!m_checkedBreakables.Contains(breakable)) { if (Random.Range(0f, 1f) < m_attackRatio) { m_target = breakable; m_rigidbody.mass = m_breakMass; m_rigidbody.GetComponent <Collider>().enabled = false; m_posFromCenter = transform.position.x - m_spawner.ProtestCenter; } m_checkedBreakables.Add(breakable); } } } } else { if ((m_target.transform.position - transform.position).magnitude < m_attackRange) { if (!m_isAttacking) { m_animController.SelectAnim(1); m_isAttacking = true; } } else { transform.position += (m_target.transform.position - transform.position).normalized * m_breakSpeed * Time.fixedDeltaTime; float dir = (m_target.transform.position - transform.position).x > 0 ? 1 : -1; transform.localScale = new Vector3(dir, 1, 1); } } }
//Checks to see if it has hit anything void CheckCollision() { checkShot = Physics2D.Raycast(transform.position, Vector2.right, distance, hittable); if (checkShot.collider != null) { if (!enemy) { if (checkShot.collider.tag == "Enemy") { Enemy hitEnemy = checkShot.collider.GetComponent <Enemy>(); if (shotgun) { hitEnemy.TakeDamage((float)damage * shotTime); } else { hitEnemy.TakeDamage(damage); } Destroy(gameObject); } else if (checkShot.collider.tag == "Breakable") { Breakable breakIt = checkShot.collider.GetComponent <Breakable>(); breakIt.DestroyBreakable(); } } else if (checkShot.collider.tag == "HomingEnemy") { HoamingEnemy hitEnemy = checkShot.collider.GetComponent <HoamingEnemy>(); if (shotgun) { hitEnemy.TakeDamage((float)damage * shotTime); } else { hitEnemy.TakeDamage(damage); } Destroy(gameObject); } else { if (checkShot.collider.tag == "Player") { Controller player = checkShot.collider.GetComponent <Controller>(); player.TakeDamage((int)damage); } } Destroy(gameObject); } }
public BreakableData(Breakable b) { indestructable = b.getIndestructable(); brokenSet = b.getBrokenSet(); second = b.getSecond(); minute = b.getMinute(); hour = b.getHour(); fix = b.getFix(); mHealth = b.getMHealth(); currentHealth = b.getCurrentHealth(); maxHealth = b.getMaxHealth(); armorClass = b.getArmorClass(); prefabName = b.getPrefabName(); }
private void Awake() { breakable = GetComponentInParent<Breakable>(); }
// Use this for initialization void Start() { breakable = this.GetComponent<Breakable>(); //photonView = transform.GetComponent<PhotonView>(); }
public void LoadToBreakable(Breakable b) { b.setIndestructable(indestructable); b.setBrokenSet(brokenSet); b.setSecond(second); b.setMinute(minute); b.setHour(hour); b.setFix(fix); b.setMHealth(mHealth); b.setCurrentHealth(currentHealth); b.setMaxHealth(maxHealth); b.setArmorClass(armorClass); b.setPrefabName(prefabName); }