public GameObject getFish() { int rndVal; for (int i = fishIdx.Length - 1; i >= 0; i--) { rndVal = RandomVariable.getRandomValue(0, i * 3); if (rndVal == 0) { return(getFish(i)); } } return(getFish(0)); }
public GameObject getTrap(Transform trans) { int val; if (RandomVariable.getRandomTrap() != 0) { return(null); } do { val = RandomVariable.getRandomValue(0, trapPrefab.Length); if (val >= DEFAULT_ENABLETRAP.GetLength(1)) { return(null); } } while (!DEFAULT_ENABLETRAP[GameAttribute.Instance.level, val] && val < DEFAULT_ENABLETRAP.GetLength(1)); return(Instantiate(trapPrefab[val], trans.position, Quaternion.identity) as GameObject); }
IEnumerator RunRandom() { int[] sels = new int[5]; int i; Vector3 temp; yield return(0); for (i = 0; i < sels.Length; i++) { sels[i] = RandomVariable.getRandomValue(0, holes.Count - 1); } for (i = 1; i < sels.Length; i++) { if (sels[i - 1] != sels[i]) { temp = holes[sels[i - 1]].position; holes[sels[i - 1]].position = holes[sels[i]].position; holes[sels[i]].position = temp; } } }
//public void reset() { //anim.SetBool ("Walk", false); //anim.SetBool ("Wave", false); //gameObject.transform.Rotate (new Vector3 (0, 180, 0)); //} //Check item collider void OnTriggerEnter(Collider col) { //Debug.Log ("onTriggerEnter()"+col.tag); if (col.tag == "Item") { if (col.GetComponent <Item> ().useAbsorb) { col.GetComponent <Item> ().useAbsorb = false; col.GetComponent <Item> ().StopAllCoroutines(); } col.GetComponent <Item> ().ItemGet(); if (++popIdx >= 6) { popIdx = 0; } mObjects[popIdx].GetComponent <PopupValue>().playPopupValue(this.gameObject.transform, col.GetComponent <Item>().scoreAdd); } else if (col.tag == "Enemy" || col.tag == "BigTrap" || col.tag == "SmallTrap") { if (!ishited) { float x; float trapX = col.transform.position.x; if (flying) { stopFly(); TrapManager.Instance.enableAllTraps(true); } if (col.tag == "Enemy") { Animator ani = col.gameObject.GetComponentInParent <Animator>(); if (ani != null) { ani.SetTrigger("Angry"); } SoundManager.Instance.PlaySE("hit_seal", false); } else { SoundManager.Instance.PlaySE("step_on", false); } ikHanlding.beHit = true; ishited = true; // 若企鵝在中線, 則隨機決定向左或向右移動 if (trapX < 1 && trapX > -1) { if (RandomVariable.getRandomValue(0, 1) == 0) { positionStand = Position.Left; ikHanlding.moveLeft = true; x = -0.5f; } else { positionStand = Position.Right; ikHanlding.moveLeft = false; x = 0.5f; } } else { if (trapX > 1) { ikHanlding.moveLeft = true; x = -0.5f; } else { ikHanlding.moveLeft = false; x = 0.5f; } positionStand = Position.Middle; } //Vector3 dd = new Vector3(x, -1.1f, -0.5f); Vector3 dd = new Vector3(x, 0.5f, col.tag == "SmallTrap" ? -3f : -5f); StartCoroutine(Knockback(dd)); } } }
void OnTriggerEnter(Collider col) { //Debug.Log ("xxx "+col.tag); if (col.tag == "Player") { if (!col.GetComponent <Controller>().flying&& (RandomVariable.getRandomFish() == 0)) { //GameObject fish = GameObject.Find("Fish[" + colorIdx + "][" + fishIdx + "]"); //fishIdx = (fishIdx + 1) % FishPool.POOL_SIZE; GameObject fish = FishPool.Instance.getFish(); float dir = RandomVariable.getRandomValue(0, 2); fish.transform.position = tr.position; Rigidbody rb = fish.GetComponent <Rigidbody>(); if (tr.position.x < -1) // 洞在左側 { if (dir == 1) { dir = 8; } else if (dir == 2) { dir = 18f; } else { dir = 0; } } else if (tr.position.x > 1) // 洞在右側 { if (dir == 1) { dir = -8; } else if (dir == 2) { dir = 0; } else { dir = -18f; } } else // 洞在中間 { if (dir == 1) { dir = 0; } else if (dir == 2) { dir = 8; } else { dir = -8; } } rb.AddForce(new Vector3(dir, 26, -15), ForceMode.Impulse); rb.isKinematic = false; rb.useGravity = true; StartCoroutine(DestroySelf(rb, dir)); } } }