Last active
January 23, 2019 03:21
-
-
Save johnlanz/62549f87f286d6d92e4827fe9e588dd1 to your computer and use it in GitHub Desktop.
Shoot Projectile using invector melee
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 UnityEngine; | |
using System.Collections; | |
public class vFireProjectile : MonoBehaviour | |
{ | |
public Transform spawnPoint; | |
public GameObject fireProjectile; | |
private vMeleeManager manager; | |
void Start() | |
{ | |
manager = GetComponentInParent<vMeleeManager>(); | |
} | |
public void Fire() | |
{ | |
//Debug.Log("Do Effect"); | |
GameObject projectile = Instantiate(fireProjectile, spawnPoint.position, manager.transform.rotation) as GameObject; | |
Transform currentTarget = Camera.main.GetComponent<vLockOnTargetControl>().currentTarget; | |
if (currentTarget) { | |
var targetHeight = currentTarget.GetComponent<CapsuleCollider>().height / 2; | |
Vector3 midPosition = new Vector3(currentTarget.position.x, currentTarget.position.y + targetHeight, currentTarget.position.z); | |
projectile.transform.LookAt(midPosition); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment