Advertisement
JonneOpettaja

StickingBullet.cs

May 15th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class StickingBullet : MonoBehaviour {
  6.  
  7.     //Add this to bullet
  8.     //Creates a joint between bullet and the target it hits
  9.     //Makes the bullet stick to its target.
  10.     //Both need to have rigidbody
  11.  
  12.     bool hasJoint = false;
  13.  
  14.     void OnCollisionEnter (Collision collision) {
  15.        
  16.         if (!hasJoint) {
  17.             gameObject.AddComponent<FixedJoint> ();
  18.             gameObject.GetComponent<FixedJoint> ().connectedBody = collision.rigidbody;
  19.             hasJoint = true;
  20.         }
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement