I am trying to instantiate an object which is going to be connected to the object it hit, the problem is that I don’t know how to execute this in the following script that I have made. It shows an error at line 13: BCE0020: An instance of type ‘UnityEngine.Joint’ is required to access non static member ‘connectedBody’.
I have a feeling that even if that error is dealt with, the script is probably wrong either way.
var ImpactSite: GameObject;
function OnCollisionEnter(collision : Collision) {
for (var contact : ContactPoint in collision.contacts)
{
if(contact.otherCollider.gameObject.name.Contains("RockLevel")){
var normal = contact.point - contact.otherCollider.transform.position;
var q = Quaternion.FromToRotation(Vector3.up, normal);
Instantiate(ImpactSite, contact.point, q);
ImpactSite.AddComponent(FixedJoint);
var otherBody = contact.otherCollider.gameObject.Rigidbody;
FixedJoint.connectedBody = otherBody;
Destroy(this);
}
}
}