// Use this for initialization
    void Start()
    {
        wc   = GetComponent <WarnController> ();
        bait = GetComponent <Bait> ();
        Para p = GameController.db.getPara(GameController.curLevel);

        bait.setLevel(p);
        ok.SetActive(false);
        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_City f = allFish [i].GetComponent <flock_City> ();
            f.id = i;
            float scale = Random.Range(2f, 4f);
            allFish [i].transform.localScale = new Vector3(scale, scale, scale);
            f.scale = scale;
        }
        goalPos = goalPrefab.transform.position;
        m_timer = 0;
        //Debug.Log ("goalPos: (" + goalPos.x + ", " + goalPos.y + ", " + goalPos.z + ")!");
    }
Exemple #2
0
    void ApplyRules()
    {
        GameObject[] gos;
        gos = globalFlock_City.allFish;
        Vector3 vcenter = center;
        Vector3 vavoid  = center;
        float   gSpeed  = 0.1f;
        Vector3 goalPos = globalFlock_City.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_City anotherFlock = go.GetComponent <flock_City> ();
                    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;
        if (m_timer >= 1)
        {
            float force = GameController.board.getPullValue();
            Debug.Log(force);
            int res = bait.getStatus(force);
            if (res == 5)
            {
                isBaiting = true;
                wc.SendWarning("Wow! The fish is baiting! Keep patient!");
                GameController.board.startMotor(GameController.curLevel);
                float minDist = 100;
                for (int i = 0; i < numFish; i++)
                {
                    flock_City f = allFish [i].GetComponentInChildren <flock_City> ();
                    if (f.dist < minDist)
                    {
                        minDist  = f.dist;
                        minIndex = i;
                        curScale = f.scale;
                    }
                }
            }

            if (res == 1)
            {
                isSuccess = true;
                wc.SendWarning("Congratulations!");
                float s         = (curScale - 2f) / (4f - 2f);
                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(GameController.curLevel);
                    }
                }
            }

            if (res == 2)
            {
                isFishing   = false;
                isBaiting   = false;
                rotateCount = 0;
                stick.transform.rotation = Quaternion.Euler(new Vector3(0, -90, 140));
                //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(0, -90, 140));
                //Debug.Log ("3");
                wc.SendWarning("Oops! The fish was scared away!");
            }

            if (res == 4)
            {
                //Debug.Log ("4");
                isFishing   = true;
                rotateCount = 1;
            }


            Debug.Log("rotateCount: " + rotateCount);
            if (isBaiting)
            {
                if (isSuccess)
                {
                    //鱼入桶
                    isSuccess   = true;
                    isFishing   = false;
                    isBaiting   = true;
                    rotateCount = 0;
                    stick.transform.rotation = Quaternion.Euler(new Vector3(0, -90, 140));
                    bitIndex = minIndex;
                }
                if (isFishing)
                {
                    //竿上抬
                    if (rotateCount <= 3)
                    {
                        stick.transform.rotation = Quaternion.Euler(new Vector3(0, -90, 140 + 10 * rotateCount));
                        rotateCount++;
                    }
                    else
                    {
                        stick.transform.rotation = Quaternion.Euler(new Vector3(0, -90, 150));
                    }
                }
            }

            //鱼放跑
            else
            {
                //Debug.Log (" waiting ");
                minIndex = -1;
            }
            m_timer = 0;
        }
    }