//public GameObject fireEffectPrefab; public override void Attack(GameObject source, Vector3 contactPoint, float AttackArg1, float AttackArg2, float AttackArg3, float AttackArg4, Collider collider, GameObject effect, GameObject effect2) { //float Damage, float timeInterval, float iteration IBurnable burnableObject = collider.GetComponent <IBurnable>(); try{ if (burnableObject != null) { burnableObject.TakeFire(AttackArg1, AttackArg2, (int)AttackArg3, contactPoint, effect); } else if ((string.Compare(collider.tag, "Enemy") == 0)) { if (collider.transform.parent.parent.parent.parent.GetComponent <IBurnable>() != null) { collider.transform.parent.parent.parent.parent.GetComponent <IBurnable>().TakeFire(AttackArg1, AttackArg2, (int)AttackArg3, contactPoint, effect); } } else { Destroy(Instantiate(effect.gameObject, contactPoint + 0.3f * Vector3.up, Quaternion.identity) as GameObject, 3f); } } catch (NullReferenceException e) {} //Destroy(source); source.SetActive(false); }
public static IBurnable[] FindBurnablesAroundPoint( Vector3 center, float radius ) { RaycastHit[] hits = Physics.SphereCastAll( origin: center, radius: radius, direction: Vector3.up, maxDistance: radius, layerMask: burnableLayerMask, queryTriggerInteraction: QueryTriggerInteraction.Collide ); List <IBurnable> burnables = new List <IBurnable>(); foreach (RaycastHit hit in hits) { IBurnable foundBurnable = hit.transform.GetComponentInChildren <IBurnable>(); if (foundBurnable != null) { burnables.Add(foundBurnable); } else { Debug.LogError("CacheBurnableNeightbors: Found burnable with no IBurnable: " + hit.transform.name); } } return(burnables.ToArray()); }
private void Hit(Vector3 position) { RaycastHit[] hits = Physics.SphereCastAll( origin: position, radius: dousingRadius, direction: Vector3.up, maxDistance: dousingRadius, layerMask: collidableLayerMask //queryTriggerInteraction: QueryTriggerInteraction.Collide ); foreach (RaycastHit hit in hits) { //if (hit.transform == this.transform) { continue; } //ignore oneself IBurnable burnable = hit.transform.GetComponentInChildren <IBurnable>(); if (burnable != null) { Douse(burnable); } } if (hitEffectPrefab != null) { Instantiate( original: hitEffectPrefab, position: position, rotation: Quaternion.identity //Random.rotation ); } Destroy(gameObject); }
void Burn(IBurnable b) { if (b == null) { return; } b.Burn(this); }
private void PropagateFire() { //Debug.LogWarning(Random.value + " Propagating fire"); //choose a random target among nearby neighbors IBurnable chosenTarget = burnableNeighbors[Random.Range(0, burnableNeighbors.Length)]; chosenTarget.ChangeVirulence(propagationRate * blazeIntensity); }
private void OnTriggerEnter(Collider other) { IBurnable component = other.GetComponent <IBurnable>(); if (component != null && component.IsBurning) { this._callback.Invoke(); } }
void OnCollisionEnter(Collision collision) { m_burnableObject = collision.transform.GetComponent <IBurnable>(); if (m_burnableObject != null) { m_burnableObject.Burn(); m_burnableObject = null; } }
void OnTriggerEnter(Collider other) { m_burnableObject = other.GetComponent <IBurnable>(); if (m_burnableObject != null) { m_burnableObject.Burn(); m_burnableObject = null; } GameObject.Destroy(gameObject); }
//ENDOF private fields //MonoBehaviour lifecycle public void Awake() { burnable = burnableTransform.GetComponent <IBurnable>(); if (burnable == null) { Debug.LogError("BurnableParticleEmitter missing burnable: " + gameObject.name); } particleEmitter = transform.GetComponent <ParticleSystem>(); if (particleEmitter == null) { Debug.LogError("BurnableParticleEmitter missing particleSystem: " + gameObject.name); } emissionController = particleEmitter.emission; }
//try several times for a standing building //if none found return last candidate private IBurnable FindArsonTarget() { IBurnable candidate = null; for (int i = 0; i < maxSearchAttempts; i++) { candidate = BurnableCache.randomBurnable; IDestructable destructable = candidate as IDestructable; if (destructable != null && !destructable.isDestroyed) { return(candidate); } } return(candidate); }
void RaycastToBurnable() { Debug.Log("rdy to burn"); Ray ray = new Ray(); if (npc) { ray.origin = transform.position; ray.direction = transform.forward; } else { ray.origin = Camera.main.transform.position; ray.direction = Camera.main.transform.forward; } RaycastHit hit; GameObject fireEffect; if (Physics.Raycast(ray, out hit)) { // Spawn particle effect at hit point if (fire != null) { fireEffect = Instantiate(fire, hit.point, Quaternion.identity); } else { fireEffect = GameObject.CreatePrimitive(PrimitiveType.Sphere); fireEffect.transform.position = hit.point; particleSystemDuration = 3f; } Destroy(fireEffect, particleSystemDuration); IBurnable burnable = hit.transform.gameObject.GetComponent <IBurnable>(); if (burnable != null) { burnable.Burns(); } } }
void Update() { Collider[] colliders = Physics.OverlapSphere(transform.position, radius); foreach (Collider hit in colliders) { if (hit == null) { continue; } GameObject g = hit.gameObject; IBurnable b = g.GetComponent <IBurnable>(); if (b != null) { Burn(b); } } }
private void Arson(IBurnable target) { Debug.LogWarning("Arson: " + target.transform.name); Ignite(target); Instantiate(original: explosionPrefab, position: target.transform.position, rotation: Quaternion.identity); float gasLeft = additionalFires; IBurnable[] burnables = BurnableCache.FindBurnablesAroundPoint(target.transform.position, currentRadius); while (gasLeft >= 0) { if (gasLeft >= 1 || Random.Range(0.0f, 1.0f) <= gasLeft) { Ignite(burnables[Random.Range(0, burnables.Length)]); } gasLeft--; } }
//ENDOF Protected hierarchy methods //private methods private void CacheBurnableNeightbors() { RaycastHit[] hits = Physics.SphereCastAll( origin: transform.position, radius: propagationDistance, direction: Vector3.up, maxDistance: propagationDistance, layerMask: burnableLayerMask, queryTriggerInteraction: QueryTriggerInteraction.Collide ); List <IBurnable> burnables = new List <IBurnable>(); foreach (RaycastHit hit in hits) { if (hit.transform == this.transform) { continue; } //ignore oneself IBurnable newBurnable = hit.transform.GetComponentInChildren <IBurnable>(); if (newBurnable != null) { burnables.Add(newBurnable); } else { Debug.LogError("CacheBurnableNeightbors: Found burnable with no IBurnable: " + hit.transform.name); } } burnableNeighbors = burnables.ToArray(); Debug.Log("Found " + burnableNeighbors.Length + " burnable neighbors"); }
public ExtinguishCommand(IBurnable burnable) { this.burnable = burnable; }
private void Ignite(IBurnable target) { target.ChangeVirulence(arsonVirulence); }
public IgniteCommmand(IBurnable burnable) { this.burnable = burnable; }
private void Douse(IBurnable burnable) { burnable.ChangeVirulence(dousingPower); }