- Home /
Question by
VenomDestroyr · Apr 28, 2016 at 05:19 AM ·
c#scripting beginnerhingejointhow-to
How To attach two rigid bodies using a hinge joint via script in game
working on a game an i have a prefab that shoots out and deletes its self after the fire button is released i need a way to make the prefab hinge to an object after it collides with an object. any help would be great. My script for shooting the object is this...
using UnityEngine; using System.Collections;
public class GrappleHookShoot : MonoBehaviour {
public GameObject GrappleHook_prefab;
public float grappleImpulse = 20f;
public GameObject Player_prefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire")){
Camera cam = Camera.main;
GameObject theGrapple = (GameObject)Instantiate(GrappleHook_prefab, cam.transform.position + cam.transform.forward, cam.transform.rotation);
theGrapple.GetComponent<Rigidbody>().AddForce(cam.transform.forward * grappleImpulse, ForceMode.Impulse);
}
}
}
Comment