Attaching an object to another within runtime
Hey to all, I'm a pretty newbie in Unity and not that familiar with C#. I haven't found an appropriate answer to my question, so i hope you guys can help me. After weeks of trying I finally got my Code running, which is basically about assembling a car within runtime. My problem is the following: I tried to pick up wheels and attach them to the car, I don't get error messages anymore but the wheel doesn't move towards the location it actually should. It cripples somewhere in the middle of the car. Obviously it should move to the end of the axis. Do you know where my fault is? Thanks in advance, Simon
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Assambly : MonoBehaviour {
public GameObject Chassis;
public GameObject FWheel;
public GameObject RWheel;
public float speed = 2;
private bool assemble = false;
public Transform[] assemblelocation;
void Update()
{
Chassis = GameObject.Find("ChassisScriptCollider(Clone)");
FWheel = GameObject.Find("BFrontWheelCollid(Clone)");
RWheel = GameObject.Find("BRareWheelCollid(Clone)");
if (assemble == true)
{
Chassis.GetComponent<Collider>().enabled = false;
Chassis.GetComponent<Rigidbody>().isKinematic = true;
FWheel.transform.position = Vector3.MoveTowards(transform.position, assemblelocation[1].position, speed * Time.deltaTime);
Chassis.transform.parent = FWheel.transform;
}
}
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
print("OnTrigger");
assemble = true;
}
}
}

Your answer
Follow this Question
Related Questions
Joystick Runtime Plug/Unplug Detection 6 Answers
Detecting whether there's a collider between 2 gameObjects in C# 1 Answer
First Person Controller Camera doesn't rotate in runtime 0 Answers
NavMesh change from walkable to NOT walkable at runtime 0 Answers
Import Normal Map at Run Time and access Border Mip Map property of texture? 0 Answers