Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BulletHandler : MonoBehaviour {
- // General Variables
- [Header("General")]
- public Rigidbody projectile;
- // Variables
- [Header("Variables")]
- public float bullet_speed;
- public float bullet_damage;
- public bool ricochet;
- // Effects
- [Header("Effects")]
- public GameObject blood_effect;
- [System.Serializable]
- public class effects {
- public string tag;
- public GameObject effect;
- public bool ricochet;
- }
- public effects[] effects_array;
- // Start is called before the first frame update
- void Start() {
- projectile.velocity = transform.forward * bullet_speed;
- }
- private void OnCollisionEnter (Collision other) {
- ContactPoint contact = other.contacts[0]; Vector3 temp_position = contact.point;
- Quaternion temp_rotation = Quaternion.LookRotation(contact.normal);
- if ( other.transform.root.gameObject.GetComponent<DismembermentHandler>() != null ) {
- other.transform.root.gameObject.GetComponent<DismembermentHandler>().dismember(other.gameObject.tag, bullet_damage, false);
- Instantiate(blood_effect, temp_position, temp_rotation, other.gameObject.transform);
- if ( !ricochet ) Destroy(gameObject);
- return;
- }
- foreach ( effects i in effects_array ) {
- if ( other.gameObject.CompareTag(i.tag) ) {
- Instantiate(i.effect, temp_position, temp_rotation);
- if ( !i.ricochet ) Destroy(gameObject);
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement