public static ProjectileInstance Create(GameObject prefab, Vector3 position, Quaternion rotation, Vector3 velocity, GameObject impactPrefab) { GameObject projectileInstanceGameObject = Instantiate(prefab, position, rotation); ProjectileInstance instance = projectileInstanceGameObject.AddComponent <ProjectileInstance>(); instance.Initialize(velocity, impactPrefab); return(instance); }
IEnumerator ShootProjectile() { while (true) { yield return(new WaitForSeconds(0.3f)); Rigidbody2D ProjectileInstance; ProjectileInstance = Instantiate(projectile, ProjectileSpawner.position, ProjectileSpawner.rotation) as Rigidbody2D; ProjectileInstance.AddForce(-ProjectileSpawner.right * 750f); SoundManager.PlaySound("laser_29"); } }
private void FireProjectile() { if (Time.time <= fireRate + timeSinceLastFire) { return; } Vector3 projectileVelocity = nozzleMarker.right * projectileSpeed; Vector3 direction = cursorController.transform.position - transform.position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward); ProjectileInstance.Create(projectilePrefab, nozzleMarker.position + projectilePrefab.transform.localScale.x / 2f * nozzleMarker.right, rotation, projectileVelocity, projectileImpactPrefab); timeSinceLastFire = Time.time; animator.SetTrigger("Shoot"); }