private void Start() { _stateMachine = _animator.GetBehaviour <StateRandom>(); _animator.keepAnimatorControllerStateOnDisable = true; _stateMachine.OnAnimationStateChanged() .TakeUntilDestroy(this) .Subscribe(_ => { var position = transform.localPosition + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f)); position = new Vector3(math.clamp(position.x, -1.7f, 1.7f), math.clamp(position.y, -1.7f, 1.5f)); _tweener = transform.DOLocalMove(position, 1.125f); }); }
private IEnumerable <Ray> CalculateRays(Vector3 origin, Vector3 direction, Vector3 up, Vector3 right, StateRandom rnd = null) { if (rnd == null) { rnd = new StateRandom(0); } for (int i = 0; i < ShotgunData.PelletCount; i++) { var rad = 360f * rnd.Next(0, 100) / 100f; var spreadX = (ShotgunData.SpreadMin + (ShotgunData.SpreadMax - ShotgunData.SpreadMin) * rnd.NextDouble()) * Mathf.Cos(rad); var spreadY = (ShotgunData.SpreadMin + (ShotgunData.SpreadMax - ShotgunData.SpreadMin) * rnd.NextDouble()) * Mathf.Sin(rad); var newDirection = direction; newDirection += up * (float)spreadY; newDirection += right * (float)spreadX; yield return(new Ray(origin, newDirection)); } }
protected override void _Start() { Random = new StateRandom(EntityId); }