/// <summary> /// Controlls the time interval and % chance for the game object to activate the ScareCow event. /// </summary> public override void Update() { OwnerPhysics.SetVelocity(AIagent.velocity); ShoutTimer += Time.deltaTime; if (ShoutTimer >= ShoutCooldown && Random.Range(1, 10) > 5) { ScareCowEventInfo scei = new ScareCowEventInfo { scarySoundLocation = Position.position }; EventHandeler.Current.FireEvent(EventHandeler.EVENT_TYPE.ScareCow, scei); ShoutTimer = 0; } }
/// <summary> /// Makes the cow run in the opposite direction from the object that scared it by activating the <see cref="AttackTheCow(int)"/> using 0 damage. /// </summary> /// <param name="eventInfo"> contains infomation brought from <see cref="EventInfo"/></param> public void ScareTheCow(EventInfo eventInfo) { if (CurrentState.GetType() != typeof(CowFleeState)) { ScareCowEventInfo scei = (ScareCowEventInfo)eventInfo; DirectionToTarget = scei.scarySoundLocation - transform.position; DistanceSqrToTarget = DirectionToTarget.sqrMagnitude; if (DistanceSqrToTarget < scareRange) { AttackTheCow(0); } } }