Skip to content

Instantly share code, notes, and snippets.

@fiskefyren
Created November 17, 2015 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiskefyren/0362897928cef2af1b59 to your computer and use it in GitHub Desktop.
Save fiskefyren/0362897928cef2af1b59 to your computer and use it in GitHub Desktop.
Projectile script
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