public Projectile SpawnProjectile(MagicWandOptions options, Vector3 position, Vector3 direction) { Projectile newProjectile = pool.GetProjectile(); newProjectile.Initialize(options, position, direction); return(newProjectile); }
public void Initialize(MagicWandOptions options, Vector2 position, Vector2 direction) { InitComponents(); this.options = options; transform.position = position; this.lifeTime = options.ProjectileLifeTime; rb.velocity = direction.normalized * options.ProjectileSpeed; gameObject.tag = options.ProjectileTag; gameObject.layer = options.ProjectileLayer; collider.gameObject.layer = options.ProjectileLayer; var main = explosion.main; main.startColor = options.color; var trailGradient = trail.colorOverLifetime; Gradient grad = new Gradient(); grad.SetKeys(new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(options.color, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) }); trailGradient.color = grad; this.direction = direction; startTime = Time.time; proj.SetActive(true); flying = true; explosion.transform.localScale = new Vector3(6 * options.ProjectileBlastAoE, 6 * options.ProjectileBlastAoE, 1.0f); lifeTimer = 0.0f; trail.Play(); dir = direction.normalized; perpendicular = Vector2.Perpendicular(dir); }