// Use this for initialization void Start() { ok.SetActive(false); wc = GetComponent <WarnController> (); bait = GetComponent <Bait> (); Para p = GameController.db.getPara(GameController.curLevel); bait.setLevel(p); isBaiting = false; isFishing = false; isSuccess = false; for (int i = 0; i < numFish; i++) { Vector3 pos = new Vector3(Random.Range(xMin, xMax), Random.Range(yMin, yMax), Random.Range(zMin, zMax)); allFish [i] = (GameObject)Instantiate(fishPrefab, pos, Quaternion.identity); flock_Island f = allFish [i].GetComponent <flock_Island> (); f.id = i; float scale = Random.Range(0.4f, 0.6f); allFish [i].transform.localScale = new Vector3(scale, scale, scale); f.scale = scale; } goalPos = goalPrefab.transform.position; m_timer = 0; }
void ApplyRules() { GameObject[] gos; gos = globalFlock_Island.allFish; Vector3 vcenter = center; Vector3 vavoid = center; float gSpeed = 0.1f; Vector3 goalPos = globalFlock_Island.goalPos; float dist; int groupSize = 0; foreach (GameObject go in gos) { if (go != this.gameObject) { dist = Vector3.Distance(go.transform.position, this.transform.position); if (dist <= neighbourDistance) { vcenter += go.transform.position; groupSize++; if (dist < 1.0f) { vavoid = vavoid + (this.transform.position - go.transform.position); } flock_Island anotherFlock = go.GetComponent <flock_Island> (); gSpeed = gSpeed + anotherFlock.speed; } } } if (groupSize > 0) { vcenter = vcenter / groupSize + (goalPos - this.transform.position); speed = gSpeed / groupSize; Vector3 direction = (vcenter + vavoid) - transform.position; if (direction != Vector3.zero) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime); } } }
// Update is called once per frame void Update() { m_timer += Time.deltaTime; //Debug.Log ("time"); //Debug.Log (m_timer); if (m_timer >= 1) { if (isBaiting) { if (isSuccess) { //鱼入桶 isSuccess = true; isFishing = false; isBaiting = true; rotateCount = 0; stick.transform.rotation = Quaternion.Euler(new Vector3(150, -60, 0)); bitIndex = minIndex; } if (isFishing) { //竿上抬 if (rotateCount <= 3) { stick.transform.rotation = Quaternion.Euler(new Vector3(150 + 5 * rotateCount, -60, 0)); rotateCount++; } else { stick.transform.rotation = Quaternion.Euler(new Vector3(160, -60, 0)); } } } //float force = GameController.board.getPullValue(); float force = h.getPullValue(); //Debug.Log (force); int res = bait.getStatus(force); if (res == 5) { isBaiting = true; GameController.board.startMotor(GameController.curLevel); float minDist = 100; for (int i = 0; i < numFish; i++) { flock_Island f = allFish [i].GetComponentInChildren <flock_Island> (); if (f.dist < minDist) { minDist = f.dist; minIndex = i; curScale = f.scale; } } wc.SendWarning("Wow! The fish is baiting! Keep patient!"); } if (res == 1) { Debug.Log("1"); isSuccess = true; h.startMotor(3); wc.SendWarning("Congratulations!"); float s = (curScale - 0.4f) / (0.6f - 0.4f); bool isUpgrade = UserController.UpdateInfo(s); if (isUpgrade) { if (GameController.curLevel == 4) { wc.SendWarning("Congratulations! You are the fishing king!"); } else { wc.SendWarning("Congratulations! You've updraded!"); ok.SetActive(true); //SceneManager.LoadScene(GameCtroller.curLevel); } } } if (res == 2) { isFishing = false; isBaiting = false; rotateCount = 0; stick.transform.rotation = Quaternion.Euler(new Vector3(150, -60, 0)); Debug.Log("2"); wc.SendWarning("Oops! The bait was eaten up!"); } if (res == 3) { isFishing = false; isBaiting = false; rotateCount = 0; stick.transform.rotation = Quaternion.Euler(new Vector3(150, -60, 0)); Debug.Log("3"); wc.SendWarning("Oops! The fish was scared away!"); } if (res == 4) { Debug.Log("4"); isFishing = true; wc.SendWarning("up up!"); rotateCount = 1; } //Debug.Log ("rotateCount: " + rotateCount); //鱼放跑 if (res == 0) { Debug.Log(" waiting "); minIndex = -1; } m_timer = 0; } }