Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BulletHandler : MonoBehaviour {
  6.  
  7. // General Variables
  8. [Header("General")]
  9. public Rigidbody projectile;
  10.  
  11. // Variables
  12. [Header("Variables")]
  13. public float bullet_speed;
  14. public float bullet_damage;
  15. public bool ricochet;
  16.  
  17. // Effects
  18. [Header("Effects")]
  19. public GameObject blood_effect;
  20.  
  21. [System.Serializable]
  22. public class effects {
  23.  
  24. public string tag;
  25. public GameObject effect;
  26. public bool ricochet;
  27.  
  28. }
  29.  
  30. public effects[] effects_array;
  31.  
  32. // Start is called before the first frame update
  33. void Start() {
  34.  
  35. projectile.velocity = transform.forward * bullet_speed;
  36.  
  37. }
  38.  
  39. private void OnCollisionEnter (Collision other) {
  40.  
  41. ContactPoint contact = other.contacts[0]; Vector3 temp_position = contact.point;
  42. Quaternion temp_rotation = Quaternion.LookRotation(contact.normal);
  43.  
  44. if ( other.transform.root.gameObject.GetComponent<DismembermentHandler>() != null ) {
  45.  
  46. other.transform.root.gameObject.GetComponent<DismembermentHandler>().dismember(other.gameObject.tag, bullet_damage, false);
  47.  
  48. Instantiate(blood_effect, temp_position, temp_rotation, other.gameObject.transform);
  49.  
  50. if ( !ricochet ) Destroy(gameObject);
  51. return;
  52.  
  53. }
  54.  
  55. foreach ( effects i in effects_array ) {
  56.  
  57. if ( other.gameObject.CompareTag(i.tag) ) {
  58.  
  59. Instantiate(i.effect, temp_position, temp_rotation);
  60.  
  61. if ( !i.ricochet ) Destroy(gameObject);
  62.  
  63. return;
  64.  
  65. }
  66.  
  67. }
  68.  
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement