/// <summary> /// Check if any scary Things are around /// </summary> private GameObject[] CheckScaryThingsAround() { scaredOfObjects.Clear(); RaycastHit[] surroundingObjects = GetVisibleObjects(); //TODO: Make sure to run away from the closest enemy foreach (RaycastHit hit in surroundingObjects) { FlammableTrait flammableTrait = hit.transform.GetComponent <FlammableTrait>(); if (flammableTrait) { if (flammableTrait.isBurning) { scaredOfObjects.Add(flammableTrait.gameObject); } continue; } WolfController wolfController = hit.transform.GetComponent <WolfController>(); if (wolfController) { scaredOfObjects.Add(wolfController.gameObject); continue; } //Other scary traits for a sheep (Like wolves, coming soon) } return(scaredOfObjects.ToArray()); }
// Update is called once per frame void Update() { if (isBurning) { //Check if the thing is hit with a water trait if (CheckForWater()) { PutOutFire(); return; } //TODO: Make this check if it can be lit on fire rather then lighting on fire //After a defined time, check if something burnable exists burnCheckTimer -= Time.deltaTime; if (burnCheckTimer <= 0) { //Random check to see if the fire spreads if (Random.Range(0f, 1f) < randomChanceToLightSomethingOnFire) { RaycastHit[] hits = Physics.SphereCastAll(this.transform.position, burnRadius, Vector3.up, 0); if (hits.Length > 0) { foreach (RaycastHit hit in hits) { if (hit.transform.gameObject.Equals(this.gameObject)) { continue; } if (Random.Range(0f, 1f) < randomChanceToLightSomethingOnFire) //TODO: Make this a seperate chance { FlammableTrait trait = hit.transform.GetComponent <FlammableTrait>(); if (trait) { trait.LightFire(); } } } } } burnCheckTimer = burnCheckTime; } burntime -= Time.deltaTime; if (burntime <= 0) { PutOutFire(); EdibleTrait trait = GetComponent <EdibleTrait>(); if (trait) { Destroy(trait); //.enabled = false; } //Destroy the fire trait to indicate that the thing isn't flammable anymore Destroy(this, 1); GetComponent <MeshRenderer>().materials[0].color = Color.grey; //TODO: Sizzle out effect } } }
private FlammableTrait IsGOBurning(GameObject go) { FlammableTrait flammableTrait = go.GetComponent <FlammableTrait>(); if (flammableTrait) { if (flammableTrait.isBurning) { return(flammableTrait); } } return(null); }
/// <summary> /// Check if any scary Things are around /// </summary> internal GameObject[] CheckScaryThingsAround() { List <GameObject> scaryThings = new List <GameObject>(); if (scaredOfObjects.Count > 0) { //Check all the scary things from last time foreach (GameObject scaredObject in scaredOfObjects) { if (Helper.DistanceToVector(this.transform.position, scaredObject.transform.position) < minimumScaredDistance) { scaryThings.Add(scaredObject); } } scaredOfObjects = scaryThings; //scaredOfObjects.Clear(); RaycastHit[] surroundingObjects = GetThingsInView(); foreach (RaycastHit hit in surroundingObjects) { if (!scaredOfObjects.Contains(hit.collider.gameObject)) { FlammableTrait flame = IsGOBurning(hit.collider.gameObject); if (flame) { scaredOfObjects.Add(flame.gameObject); } } //Other scary traits for a wolf } } else { //scaredOfObjects.Clear(); RaycastHit[] surroundingObjects = GetThingsInView(); foreach (RaycastHit hit in surroundingObjects) { FlammableTrait flame = IsGOBurning(hit.collider.gameObject); if (flame) { scaredOfObjects.Add(flame.gameObject); } //Other scary traits for a wolf } } return(scaredOfObjects.ToArray()); }