//---------------------------------------------------------------------------------------------------------------- // Update is called once per frame void Update() { if (ctunity == null || ctclient == null) { Debug.Log(name + ", oops no ctunity/ctlient!"); return; // async } if (!ctunity.activePlayer(gameObject)) { return; } launchInterval = ctclient.getCustom("dt", launchInterval); stopWatch += Time.deltaTime; if (stopWatch >= launchInterval) { String missile = ctclient.getCustom("M", Missile); // optional custom missile Ilaunch = ctclient.getCustom("N", Ilaunch); Nlaunch = ctclient.getCustom("Nmax", Nlaunch); // Debug.Log(name + ": Nlaunch: " + Nlaunch+", launchInterval: "+launchInterval); if (Nlaunch != 0 && Ilaunch >= Nlaunch) { return; } ctunity.deployInventory(missile, CTunity.fullName(gameObject) + "/R-" + Ilaunch); Ilaunch++; ctclient.putCustom("N", Ilaunch); stopWatch = 0; } }
//---------------------------------------------------------------------------------------------------------------- // Update is called once per frame void FixedUpdate() { if (rb == null) // init async? { rb = GetComponent <Rigidbody>(); // start with velocity of grandparent (?) if (rb != null) { Rigidbody pprb = transform.parent.transform.parent.gameObject.GetComponent <Rigidbody>(); if (pprb != null) { rb.velocity = pprb.velocity; } } } if (!ctunity.activePlayer(gameObject)) { return; } // save fuel and flightTime with CT float fuel = ctclient.getCustom("Fuel", fuelTime); float flightTime = ctclient.getCustom("Age", 0f); // Debug.Log(CTunity.fullName(gameObject) + ", fuel: " + fuel + ", fueltime: " + fuelTime+", flightTime: "+flightTime); fuel -= Time.deltaTime; // fuel units = RT sec if (fuel < 0) { fuel = 0; } flightTime += Time.deltaTime; ctclient.putCustom("Fuel", fuel.ToString("0.00")); ctclient.putCustom("Age", flightTime.ToString("0.00")); if (fuel > 0) { float noiseX = (float)random.NextDouble() * wobbleFactor; // bit of uncertainty so rockets don't perfectly "stack" float noiseZ = (float)random.NextDouble() * wobbleFactor; rb.AddRelativeForce(new Vector3(noiseX, 1f, noiseZ) * ForceFactor); } else if (flightTime > boomTime) { // Debug.Log(name + ": BOOM!"); ctunity.clearObject(gameObject); } }
//---------------------------------------------------------------------------------------------------------------- void doCollision(Collider other) { if (debug) { Debug.Log(name + ": doCollision, showHP: " + showHP + ", kso: " + kso); } if (!showHP || kso == null) { return; // no game } // if (!showHP || kso == null || !ctunity.activePlayer(gameObject)) return; // no game String myName = CTunity.fullName(gameObject); String otherName = CTunity.fullName(other.gameObject); if (ctunity == null) { ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); } if (other.gameObject == null || ctunity == null) { Debug.Log(name + ": OnTrigger null other object: " + other.name); return; } // compare hit levels to see who wins HP = ctclient.getCustom("HP", HP); int damage = (int)Math.Ceiling((float)kso.ATK / (float)AC); HP -= damage; if (HP < 0) { HP = 0; } ctclient.putCustom("HP", HP); if (HP <= 0) { if (killParent) // can't destroyImmediate inside collision callback { ctunity.clearObject(gameObject.transform.parent.gameObject, false); } else { ctunity.clearObject(gameObject, false); } } // Debug.Log(myName + ", collide with: " + otherName+", damage: "+damage+", kso.ATK: "+kso.ATK+", AC: "+AC); if (scaleSize) { targetScale = initialScale * (0.1f + 0.9f * ((float)(HP) / (float)initialHP)); } }