private void RemoveCubimal() { _state = RaceTrackState.Ready; _cubimal.OnPickedUp -= HandleCubimalPickedUp; _cubimal.OnStopped -= HandleCubimalStopped; _cubimal = null; OnCubimalRemoved?.Invoke(); }
private IEnumerator OpenBoxSequence() { OnOpened?.Invoke(); _state = CubimalBoxState.Opening; _rigidbody.isKinematic = true; _animator.SetTrigger(OpenBool); Hand hand = _hand; GrabTypes?currentGrabTypes = GrabTypes.None; Hand.AttachmentFlags?currentAttachmentFlags = Hand.AttachmentFlags.ParentToHand | Hand.AttachmentFlags.TurnOnKinematic | Hand.AttachmentFlags.DetachFromOtherHand; if (hand != null) { currentGrabTypes = hand.currentAttachedObjectInfo?.grabbedWithType; currentAttachmentFlags = hand.currentAttachedObjectInfo?.attachmentFlags; } yield return(new WaitForSeconds(0.25f)); Cubimal cubimal = Instantiate(_cubimalPrefabs[Random.Range(0, _cubimalPrefabs.Length)], transform.position, transform.rotation).GetComponent <Cubimal>(); cubimal.Spawn(hand != null); if (hand != null) { if (hand.currentAttachedObject == gameObject) { hand.DetachObject(gameObject, true); } hand.AttachObject(cubimal.gameObject, currentGrabTypes.GetValueOrDefault(), currentAttachmentFlags.GetValueOrDefault()); } _particleSystem.transform.SetParent(null, true); _particleSystem.Play(); _particleSystem = null; yield return(new WaitForSeconds(0.25f)); Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (_cubimal != null || _state != RaceTrackState.Ready) { return; } Cubimal cubimal = other.gameObject.GetComponentInParent <Cubimal>(); if (cubimal != null && cubimal.CanRace()) { _cubimal = cubimal; _cubimal.OnPickedUp += HandleCubimalPickedUp; _cubimal.OnStopped += HandleCubimalStopped; _positionSequence = StartCoroutine(PositionCubimalSequence()); } }
private void OnTriggerEnter(Collider other) { if (_state != RaceState.Racing) { return; } Cubimal cubimal = other.gameObject.GetComponentInParent <Cubimal>(); if (cubimal != null) { foreach (RaceTrack raceTrack in _raceTracks) { if (raceTrack.Cubimal == cubimal) { FinishRace(raceTrack); return; } } } }