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 StickingBullet : MonoBehaviour {
- //Add this to bullet
- //Creates a joint between bullet and the target it hits
- //Makes the bullet stick to its target.
- //Both need to have rigidbody
- bool hasJoint = false;
- void OnCollisionEnter (Collision collision) {
- if (!hasJoint) {
- gameObject.AddComponent<FixedJoint> ();
- gameObject.GetComponent<FixedJoint> ().connectedBody = collision.rigidbody;
- hasJoint = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement