void Update() { // If there was a puppet that was entered... if (m_puppetJustEntered) { if (m_puppetJustEntered.transform.position == m_puppetJustEnteredLastPosition) m_idle = true; else { m_idle = false; m_idleWaitingTime = 0; } m_puppetJustEnteredLastPosition = m_puppetJustEntered.transform.position; // But it just leaves the box, remove it if (!m_puppets.Exists(toFind => toFind == m_puppetJustEntered)) m_puppetJustEntered = null; } // Make action when player stops over the box if (m_idle && m_puppetJustEntered) { m_idleWaitingTime += Time.deltaTime; // If it's true 3 seconds if (m_idleWaitingTime > 3) { BoxAction(); m_puppetJustEntered = null; } } }
/// <summary> /// MUST BE IMPLEMENTED BY CHILDREN! MUST BE CALLED FOR LOGIC CHECK! /// Box action logic. /// </summary> protected virtual bool OnTriggerAction(Collider other) { Player.PuppetController p = other.GetComponent<Player.PuppetController>(); // If object is already inside the collider / box if (m_puppets.Exists(toFind => toFind == p)) return true; m_puppetJustEntered = other.GetComponent<Player.PuppetController>(); // If object is not already inside the collider / box, then add it AddPuppetInsideBox(p); if (Manager.Board.Instance.IsRespawning()) return true; else return false; }