Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created October 5, 2017 23:26
Show Gist options
  • Save unity3dcollege/69eae93cba5be936f3cabb0a69586635 to your computer and use it in GitHub Desktop.
Save unity3dcollege/69eae93cba5be936f3cabb0a69586635 to your computer and use it in GitHub Desktop.
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);
}
}
}
@meatball-san
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment