- Home /
Attachment of equipment for transport
When the transport runs up to the object trigger, when you press a key in me, the script that comes to me is parental, the problem is that there is a space between them here here is the script
public class Trigger : MonoBehaviour {
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("Player"))
{
if (Input.GetKeyDown(KeyCode.E))
{
transform.SetParent(other.transform);
}
}
}
void FixedUpdate()
{
if (Input.GetKey(KeyCode.R)) {
transform.parent = null;
}
}
}
The question is, how is it possible that when you press a key, the script and the hardware will be placed in this way! Is it possible with the help of animation? Or is there another way!
Your first image doesn't work, so we can't really see what your current result looks like.
Based on my assumption of what it looks like I will throw some possible solution here.
Your equipment should have a pivot point in position where you want to attach it to something. Your vehicle should have an empty child which would be placed in position where you want to attach something. Then, when you parent your equipment to that child set local position to Vector3.zero.
I understood how this should look, but I can not understand how to correctly write this in the script! Now, if something is the same photo when the child project to the parent