/// <summary> /// When objects leave the planet orbit, they cease to be children of _self, so they stop rotating when _self spins. /// </summary> private void OnTriggerExit(Collider other) { if (!other.gameObject.tag.Contains("|Player|")) { return; } print("EXIT planet collide! " + gameObject.transform.parent.name); other.transform.SetParent(_playerOriginalParent); // when exit, reposition player if (!_isLit) { return; } if (!other.gameObject.tag.Contains("|Player|")) { return; } print("exit planet when star lit"); // _isOnPlanet = false; OnRidePlanet?.Invoke(_isOnPlanet); CancelInvoke(nameof(AdjustRotation)); }
//TODO: mark these comments as a TODO item, add them to documentation, or delete them. // need to check if the star is lit or not // check if create star or destroy star is on trigger /// <summary> /// When an object capable of orbiting enters the collider, it becomes a child of _self. /// </summary> /// <remarks> /// Since players can move, we need to regularly call AdjustRotation() to keep a player orbiting /// all the way around the object. /// </remarks> private void OnTriggerEnter(Collider other) { if (!other.gameObject.tag.Contains("|Player|")) { return; } print("collide with a planet! " + gameObject.transform.parent.name); _player = other; _playerOriginalParent = _player.transform.parent.transform; print("player original parent -- " + _playerOriginalParent.name); // player can orbit the planet only if the star is lit if (!_isLit) { return; } print("!!!!!!!!!!! star is lit and ready to reveal the GUI"); _self.LookAt(other.transform.position); other.gameObject.transform.SetParent(transform); _isOnPlanet = true; OnRidePlanet?.Invoke(_isOnPlanet); // TODO: remove adjust rotation InvokeRepeating(nameof(AdjustRotation), 1.0f, 1.0f); }