//accessing the very beginning of runtime public void Awake() { timer = Random.Range(0, 20); //setting the emotional state for agents to be random on start emotionalState = (EmotionalStates)UnityEngine.Random.Range(0, System.Enum.GetValues(typeof(EmotionalStates)).Length); material = gameObject.GetComponent <Renderer>().material; }
public void Update() { AssignColour(this.gameObject); if (timer < 10) { emotionalState = (EmotionalStates)UnityEngine.Random.Range(0, System.Enum.GetValues(typeof(EmotionalStates)).Length); } }
void OnCollision(Collision collider) { if (emotionalState == EmotionalStates.Happy) { if (collider.transform.tag == "Sad" && RNG < 4) { emotionalState = EmotionalStates.Happy; } else if (emotionalState == EmotionalStates.Scared && RNG < 4) { emotionalState = EmotionalStates.Scared; } else { emotionalState = EmotionalStates.Sad; } } }
private void Update() { timer += Time.deltaTime; /*Forcing all desires to be clamped between a value of 0 and 100 * while ensuring they decrease over time multiplied by the "Loss" value attached to each desire*/ foreach (var desire in AllDesires) { desire.Value = Mathf.Clamp(desire.Value - Time.deltaTime * desire.Loss, 0, 99); } var maxDesire = AllDesires.OrderBy(d => d.NormalisedImportance).First(); //Setting maxDesire to equal the first or highest desire seekTarget.SetTarget(maxDesire.Target.position, maxDesire.WaitTimer); //Setting the agents target to the position of the maxDesire /*Ensuring the agent drinks AND eats if it is at either the fridge or the water bottle * as this makes logical sense since they are near each other */ Vector3 atFridge = Hunger.Target.position - transform.position; if (atFridge.magnitude < targetRange) { if (transform.position == GameObject.FindObjectOfType <Agent>().transform.position) { if (getRandom <= 2) { emotionalState = EmotionalStates.Angry; } else { emotionalState = EmotionalStates.Happy; } } Hunger.Value += Hunger.Gain; Thirst.Value += Thirst.Gain; } Vector3 atDrink = Thirst.Target.position - transform.position; if (atDrink.magnitude < targetRange) { Hunger.Value += Hunger.Gain; Thirst.Value += Thirst.Gain; } Vector3 atConsole = Boredom.Target.position - transform.position; if (atConsole.magnitude < targetRange) { emotionalState = EmotionalStates.Happy; if (getRandom <= 2) { emotionalState = EmotionalStates.Angry; } else { emotionalState = EmotionalStates.Happy; } } foreach (var desire in AllDesires) { Vector3 distance = desire.Target.position - transform.position; if (distance.magnitude < targetRange) { desire.Value += desire.Gain; } } SetColours(); AssignValue(); CollisionChecks(); print(getRandom); }
void CollisionChecks() { getRandom = UnityEngine.Random.Range(0, 3); //Happy if (emotionalState == EmotionalStates.Happy) { if (transform.position.x < GameObject.FindGameObjectWithTag("Sad").transform.position.x) { emotionalState = (EmotionalStates)UnityEngine.Random.Range(0, System.Enum.GetValues(typeof(EmotionalStates)).Length); } else if (transform.position.x < GameObject.FindGameObjectWithTag("Scared").transform.position.x) { if (getRandom <= 1) { emotionalState = EmotionalStates.Scared; } else { emotionalState = EmotionalStates.Happy; } } else if (transform.position.x < GameObject.FindGameObjectWithTag("Angry").transform.position.x) { if (getRandom <= 2) { emotionalState = EmotionalStates.Scared; } else { emotionalState = EmotionalStates.Angry; } } } //Sad if (emotionalState == EmotionalStates.Sad) { if (transform.position.x < GameObject.FindGameObjectWithTag("Scared").transform.position.x) { if (getRandom <= 1) { emotionalState = EmotionalStates.Scared; } else { emotionalState = EmotionalStates.Sad; } } else if (transform.position.x < GameObject.FindGameObjectWithTag("Angry").transform.position.x) { if (timer >= 5f) { emotionalState = (EmotionalStates)UnityEngine.Random.Range(0, System.Enum.GetValues(typeof(EmotionalStates)).Length); timer = 0; } if (getRandom <= 1) { emotionalState = EmotionalStates.Scared; } else if (getRandom == 2) { emotionalState = EmotionalStates.Angry; } else { emotionalState = EmotionalStates.Sad; } } } //Angry if (emotionalState == EmotionalStates.Angry) { if (timer >= 5f) { if (getRandom <= 2) { emotionalState = EmotionalStates.Happy; timer = 0; } else { emotionalState = EmotionalStates.Sad; timer = 0; } } if (transform.position.x < GameObject.FindGameObjectWithTag("Sad").transform.position.x) { if (getRandom <= 2) { emotionalState = EmotionalStates.Angry; } else { emotionalState = EmotionalStates.Sad; } } else if (transform.position.x < GameObject.FindGameObjectWithTag("Scared").transform.position.x) { if (getRandom <= 3) { emotionalState = EmotionalStates.Scared; } else { emotionalState = EmotionalStates.Angry; } } else if (transform.position.x < GameObject.FindGameObjectWithTag("Angry").transform.position.x) { emotionalState = EmotionalStates.Angry; } } //Scared if (emotionalState == EmotionalStates.Scared) { if (transform.position.x < GameObject.FindGameObjectWithTag("Sad").transform.position.x) { emotionalState = (EmotionalStates)UnityEngine.Random.Range(0, System.Enum.GetValues(typeof(EmotionalStates)).Length); } else if (transform.position.x < GameObject.FindGameObjectWithTag("Scared").transform.position.x) { if (getRandom <= 1) { emotionalState = EmotionalStates.Scared; } else { emotionalState = EmotionalStates.Happy; } } else if (transform.position.x < GameObject.FindGameObjectWithTag("Angry").transform.position.x) { if (getRandom <= 2) { emotionalState = EmotionalStates.Scared; } else { emotionalState = EmotionalStates.Angry; } } } }