using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; using Janus; [Script(ScriptRole.Logic)] public class DinoNestLogic : MonoBehaviour { public float FryingDuration; public Timeline<GameObject> OwnerDino; public Timeline<bool> Frying; void Awake () { OwnerDino = Sync.CreateDiscreteState<GameObject>(); Frying = Sync.CreateDiscreteState<bool>(); } void OnHit (HitInfo hit) { // Return if the nest is already frying an egg // Players will have to wait for the animation/scoring to occur before placing another egg in the nest if (Frying.LastValue) return; if (hit.SourceObject == null) return; // Check that this is the home nest of the source object (the Dino that triggered the hit) if (hit.SourceObject != OwnerDino.LastValue) return; DinoLogic dino = hit.SourceObject.GetComponent<DinoLogic>(); // Return if the dino is not holding an egg at all if (!dino.HasEgg.LastValue) return; dino.HasEgg[0] = false; StartCoroutine(FryEggAsync(hit.SourceObject)); } IEnumerator FryEggAsync(GameObject playerDino) { Frying[0] = true; yield return new WaitForSeconds(FryingDuration); Frying[0] = false; if (playerDino != null) { playerDino.GetComponent<DinoLogic>().Score[0] += 1; } } }