//---------------------------------------------------------------------------------------------------------------- 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)); } }
//---------------------------------------------------------------------------------------------------------------- // 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 OnGUI() { Event m_Event = Event.current; if (m_Event.button != 0) { return; // only check left-mouse button? } if (!ctunity.activePlayer(gameObject)) { return; } if (EventSystem.current.IsPointerOverGameObject()) { return; // no deal if clicking on UI element } if ((m_Event.type == EventType.MouseDown && m_Event.clickCount == 2) /* || (m_Event.button == 1 && m_Event.type == EventType.MouseDown ) * /* || (m_Event.type == EventType.MouseDrag) */) { RaycastHit hit; Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, maxDistance)) { if (hit.collider.gameObject == gameObject) // double click delete target { Debug.Log(name + " Buh Bye"); ctunity.clearObject(gameObject); return; } if (hit.collider.gameObject.GetComponent <CTclient>() == null) // no target CTclient player objects { targetPos = hit.point; } // Debug.Log("SET targetPos: " + targetPos + ", targetObj: " + CTunity.fullName(targetObj)); // GameObject.Find("Main Camera").GetComponent<maxCamera>().setTarget(hit.transform); } m_Event.Use(); } }
//---------------------------------------------------------------------------------------------------------------- // poof on collide void OnTriggerEnter(Collider other) { // gameObject.SetActive(false); ctunity.clearObject(gameObject); }