Projectile script
This file contains 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 LaserProjectile : MonoBehaviour { | |
| public float speed = 2f; //speed at which the projectile travels in world space | |
| public int damage = 25; //damage dealt to other objects this projectile hits | |
| private Transform thisTransform; //cached transform for this projectile | |
| public Transform lasterHitFXPrefab; | |
| void Start () { | |
| thisTransform = transform; | |
| } | |
| void Update () { | |
| thisTransform.position += Time.deltaTime * speed * thisTransform.forward; | |
| } | |
| void OnCollisionEnter (Collision collisionTemp) { | |
| if(collisionTemp.gameObject.tag == "Enemy") { | |
| collisionTemp.gameObject.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver); | |
| ContactPoint contact = collisionTemp.contacts[0]; | |
| Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal); | |
| Vector3 pos = contact.point; | |
| Instantiate (lasterHitFXPrefab, pos, rot); | |
| Destroy (gameObject); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment