private void ResetPosition(BridgeMaker InOtherMaker, ref Vector3 InPosition) { Vector2 begin_1 = new Vector2(Begin.x, Begin.z); Vector2 end_1 = new Vector2(End.x, End.z); Vector2 begin_2 = new Vector2(InOtherMaker.Begin.x, InOtherMaker.Begin.z); Vector2 end_2 = new Vector2(InOtherMaker.End.x, InOtherMaker.End.z); Vector2 result = Math.intersectionOf2Lines(begin_1, end_1, begin_2, end_2); InPosition.x = result.x; InPosition.z = result.y; InPosition.y += 15; }
void OnTriggerEnter(Collider other) { BridgeMaker otherMaker = other.gameObject.GetComponent <BridgeMaker>(); if (otherMaker && otherMaker.type == AI_TYPE.SHIP && IsEnableMaker()) { Vector3 pos = other.ClosestPoint(transform.position); ResetPosition(otherMaker, ref pos); BridgeController.Instance.BuildNewBridge(type, pos, transform.rotation); } // Make sure the river is clear if (other.gameObject.layer == LayerMask.NameToLayer("Building")) { Destroy(other.gameObject); } }