private void updateGrenadeAimAndPreview() { if (_motor.IsAlive && _motor.IsReadyToThrowGrenade && _motor.CurrentGrenade != null) { GrenadeDescription desc; desc.Gravity = _motor.Grenade.Gravity; desc.Duration = _motor.PotentialGrenade.Timer; desc.Bounciness = _motor.PotentialGrenade.Bounciness; var verticalAngle = Mathf.Min(GrenadeVerticalAngleInput + ThrowAngleOffset, MaxThrowAngle); var velocity = _motor.Grenade.MaxVelocity; if (verticalAngle < 45) { velocity *= Mathf.Clamp01((verticalAngle + 15) / 45f); } _grenadePathLength = GrenadePath.Calculate(GrenadePath.Origin(_motor, GrenadeHorizontalAngleInput), GrenadeHorizontalAngleInput, verticalAngle, velocity, desc, _grenadePath, _motor.Grenade.Step); _hasGrenadePath = true; if (_explosionPreview == null && ExplosionPreview != null) { _explosionPreview = GameObject.Instantiate(ExplosionPreview); _explosionPreview.transform.parent = null; _explosionPreview.SetActive(true); } if (_explosionPreview != null) { _explosionPreview.transform.localScale = Vector3.one * _motor.PotentialGrenade.ExplosionRadius * 2; _explosionPreview.transform.position = _grenadePath[_grenadePathLength - 1]; } if (_pathPreview == null && PathPreview != null) { _pathPreview = GameObject.Instantiate(PathPreview); _pathPreview.transform.parent = null; _pathPreview.SetActive(true); } if (_pathPreview != null) { _pathPreview.transform.position = _grenadePath[0]; var path = _pathPreview.GetComponent <PathPreview>(); if (path != null) { path.Points = _grenadePath; path.PointCount = _grenadePathLength; } } } else { if (_explosionPreview != null) { GameObject.Destroy(_explosionPreview); _explosionPreview = null; } if (_pathPreview != null) { GameObject.Destroy(_pathPreview); _pathPreview = null; } _hasGrenadePath = false; } }
private void Update() { if (_isActivating) { _activateTimer -= Time.deltaTime; if (_activateTimer < float.Epsilon) { _isActivating = false; _isActivated = true; GrenadeList.Register(this); _timer = Timer; } } if (_isActivated) { if (_timer < float.Epsilon) { explode(); } else { _timer -= Time.deltaTime; if (_timer < Timer - PreviewTime) { if (_preview == null) { _preview = GameObject.Instantiate(ExplosionPreview); _preview.transform.parent = null; _preview.SetActive(true); } if (_preview != null) { _preview.transform.localScale = Vector3.one * ExplosionRadius * 2; _preview.transform.position = transform.position; } } else if (_preview != null) { GameObject.Destroy(_preview); _preview = null; } } } if (_isFlying) { var position = transform.position; var previousOffset = _offset; _offset = Vector3.Lerp(_offset, Vector3.zero, Time.deltaTime * 2); position += _offset - previousOffset; GrenadePath.Step(ref position, ref _velocity, Time.deltaTime, _gravity, Bounciness); transform.position = position; } }