Created
October 5, 2017 23:26
-
-
Save unity3dcollege/69eae93cba5be936f3cabb0a69586635 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
public class Launcher : MonoBehaviour | |
{ | |
[SerializeField] | |
private Transform[] firePoints; | |
[SerializeField] | |
private Rigidbody projectilePrefab; | |
[SerializeField] | |
private float launchForce = 700f; | |
public void Update() | |
{ | |
if (Input.GetButtonDown("Fire1")) | |
{ | |
LaunchProjectile(); | |
} | |
} | |
private void LaunchProjectile() | |
{ | |
foreach (var firePoint in firePoints) | |
{ | |
var projectileInstance = Instantiate( | |
projectilePrefab, | |
firePoint.position, | |
firePoint.rotation); | |
projectileInstance.AddForce(firePoint.forward * launchForce); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot! This code really saved me XD. Been working on this project and was hitting the deadline just to find I don't know how to aim the bullet according with Player's perspective XD.