private void Awake() { kplane = GetComponent <KinematicPlane>(); actor = GetComponent <Actor>(); if (kplane != null) { kplane.enabled = false; Debug.Log("Dissabled kplane on " + gameObject.name); } else { Debug.Log("Could not find kplane on " + gameObject.name); } rb = GetComponent <Rigidbody>(); rb.isKinematic = true; FloatingOriginTransform originTransform = GetComponent <FloatingOriginTransform>(); if (originTransform == null) { originTransform = gameObject.AddComponent <FloatingOriginTransform>(); } originTransform.SetRigidbody(rb); Networker.RigidbodyUpdate += RigidbodyUpdate; }
private void Reparent() { GameObject go = new GameObject(); Transform childTf = go.transform; childTf.position = transform.position; childTf.rotation = transform.rotation; childRb = go.AddComponent <Rigidbody>(); childRb.isKinematic = true; childRb.interpolation = RigidbodyInterpolation.Interpolate; FloatingOriginTransform fo = go.AddComponent <FloatingOriginTransform>(); fo.SetRigidbody(childRb); Actor[] actors = GetComponentsInChildren <Actor>(true); foreach (Actor actor in actors) { actor.SetParentRigidbody(childRb); Debug.Log($"Set rigidbody on actor: {actor.gameObject.name}"); } Gun[] guns = GetComponentsInChildren <Gun>(true); foreach (Gun gun in guns) { gun.SetParentRigidbody(childRb); Debug.Log($"Set rigidbody on gun: {gun.gameObject.name}"); } CarrierCatapult[] cats = GetComponentsInChildren <CarrierCatapult>(true); foreach (CarrierCatapult cat in cats) { cat.parentRb = childRb; Debug.Log($"Set rigidbody on cat: {cat.gameObject.name}"); } MovingPlatform[] platforms = GetComponentsInChildren <MovingPlatform>(true); foreach (MovingPlatform platform in platforms) { platform.SetParentRigidbody(childRb); Debug.Log($"Set rigidbody on platform: {platform.gameObject.name}"); } //Runway[] runways = GetComponentsInChildren<Runway>(); //foreach (Runway runway in runways) //{ // runway.parentActor = childRb; //} int childCount = tf.childCount; for (int i = 0; i < childCount; i++) { tf.GetChild(0).parent = childTf; } childTf.parent = transform; }
private void Awake() { rb = GetComponent <Rigidbody>(); FloatingOriginTransform originTransform = GetComponent <FloatingOriginTransform>(); if (originTransform == null) { originTransform = gameObject.AddComponent <FloatingOriginTransform>(); } originTransform.SetRigidbody(rb); Networker.RigidbodyUpdate += RigidbodyUpdate; }
void SpawnRandomAircraft(Vector3D pos, Vector3 dir) { if (mpMode && host == false) { return; } if (spawnableAircraft.Count > 0) { GameObject aircraft = spawnableAircraft[UnityEngine.Random.Range(0, spawnableAircraft.Count)].SpawnAircraft(); FloatingOriginTransform floatingTransform = aircraft.AddComponent <FloatingOriginTransform>(); if (floatingTransform != null) { floatingTransform.SetRigidbody(aircraft.GetComponent <Rigidbody>()); } aircraft.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; TrafficAI_Transport ai = aircraft.AddComponent <TrafficAI_Transport>(); GameObject unitSpawner = new GameObject(); ai.aircraft.unitSpawner = unitSpawner.AddComponent <UnitSpawner>(); Traverse unitSpawnerTraverse = Traverse.Create(ai.aircraft.unitSpawner); unitSpawnerTraverse.Field("_spawned").SetValue(true); Traverse aircraftSpawnerTraverse = Traverse.Create(ai.aircraft); aircraftSpawnerTraverse.Field("taxiSpeed").SetValue(ai.aircraft.aiPilot.taxiSpeed); ai.Spawn(pos, dir); Debug.Log("Spawned " + aircraft.name + " as air traffic"); activeAircraftAmmount++; if (mpMode) { Debug.Log("MP is enabled, networking this aircraft!"); MPSetUpAircraft(ai.aircraft.actor); } } else { Debug.Log("No aircraft were available, cannot spawn a traffic aircraft."); } }