void Create_Hub(string direction, Vector3 position) { //Create gameobject & Set transform GameObject hubObject = new GameObject("Hub_" + direction); hubObject.transform.parent = thisTransform; hubObject.transform.localPosition = position; hubObject.transform.localRotation = Quaternion.identity; // Mesh MeshFilter meshFilter = hubObject.AddComponent <MeshFilter> (); if (direction == "L") { meshFilter.mesh = Hub_Mesh_LProp.objectReferenceValue as Mesh; } else { meshFilter.mesh = Hub_Mesh_RProp.objectReferenceValue as Mesh; } MeshRenderer meshRenderer = hubObject.AddComponent <MeshRenderer> (); Material[] materials = new Material [Hub_Materials_NumProp.intValue]; for (int i = 0; i < materials.Length; i++) { materials [i] = Hub_MaterialsProp.GetArrayElementAtIndex(i).objectReferenceValue as Material; } meshRenderer.materials = materials; // Rigidbody Rigidbody rigidbody = hubObject.AddComponent <Rigidbody> (); rigidbody.mass = Hub_MassProp.floatValue; // HingeJoint HingeJoint hingeJoint; hingeJoint = hubObject.AddComponent <HingeJoint> (); hingeJoint.connectedBody = thisTransform.Find("Axle_Shaft").GetComponent <Rigidbody> (); if (direction == "L") { hingeJoint.anchor = new Vector3(-Hub_Anchor_Offset_XProp.floatValue, 0.0f, Hub_Anchor_Offset_ZProp.floatValue); } else { hingeJoint.anchor = new Vector3(Hub_Anchor_Offset_XProp.floatValue, 0.0f, Hub_Anchor_Offset_ZProp.floatValue); } hingeJoint.axis = new Vector3(0.0f, 1.0f, 0.0f); hingeJoint.useSpring = true; JointSpring jointSpring = hingeJoint.spring; jointSpring.spring = Hub_SpringProp.floatValue; hingeJoint.spring = jointSpring; // SphereCollider SphereCollider sphereCollider; sphereCollider = hubObject.AddComponent <SphereCollider> (); sphereCollider.radius = Hub_Collider_RadiusProp.floatValue; // Steer_Wheel_CS if (Steer_FlagProp.boolValue) { Steer_Wheel_CS steerScript = hubObject.AddComponent <Steer_Wheel_CS> (); if (Reverse_FlagProp.boolValue) { steerScript.Reverse = -1.0f; } else { steerScript.Reverse = 1.0f; } steerScript.Max_Angle = Max_AngleProp.floatValue; steerScript.Rotation_Speed = Rotation_SpeedProp.floatValue; } // Set Layer hubObject.layer = Layer_Settings_CS.Reinforce_Layer; }
public override void Prepare(Steer_Wheel_CS steerScript) { this.steerScript = steerScript; aiScript = transform.root.GetComponentInChildren <AI_CS>(); }
public virtual void Prepare(Steer_Wheel_CS steerScript) { this.steerScript = steerScript; }