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().enabled = false;
Chassis.GetComponent().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;
}
}
}
![alt text][1]
*
[1]: /storage/temp/107564-wheels.png
↧