コード例 #1
0
ファイル: Algae.cs プロジェクト: CWardee/CreativeTechProject
    void OnCollisionEnter(Collision collision)
    {
        float spawnRadius = gameManager.SpawnRadius;

        //Check for a match with the specified name on any GameObject that collides with your GameObject
        if (collision.gameObject.name == "Fish")
        {
            fishScript = collision.gameObject.GetComponent <ModuleMovemet>();
            if (fishScript != null)
            {
                fishScript.hunger = 0;
                fishScript.hungry = false;

                this.gameObject.transform.position = new Vector3(Random.Range(-spawnRadius, spawnRadius),
                                                                 -spawnRadius,
                                                                 Random.Range(-spawnRadius, spawnRadius));
            }
        }

        if (collision.gameObject.name == "Obstactle")
        {
            this.gameObject.transform.position = new Vector3(Random.Range(-spawnRadius, spawnRadius),
                                                             Random.Range(-spawnRadius / 1.5f, -spawnRadius / 1.5f),
                                                             Random.Range(-spawnRadius, spawnRadius));
        }
    }
コード例 #2
0
    private void OnTriggerEnter(Collider other)
    {
        // if algea found
        if (other.name == "Algae" && other != this.gameObject && hungry)
        {
            foodToEat = other.gameObject;
        }

        //mating
        if (other.name == "Fish" && !hungry)
        {
            numOfFish++;
            fishScript = other.GetComponent <ModuleMovemet>();

            if (fishScript.mating && mating && this.gameObject.transform.position.y < -radius + 25 && female == false)
            {
                if (female == false && fishScript.female == true)
                {
                    mating     = false;
                    hide       = false;
                    matingUrge = 0;

                    Instantiate(this.gameObject, new Vector3(this.gameObject.transform.position.x + 1,
                                                             this.gameObject.transform.position.y,
                                                             this.gameObject.transform.position.z), Quaternion.Euler(Random.Range(-180f, 180f), Random.Range(-180f, 180f), Random.Range(-180f, 180f)));
                }


                else if (female == true && fishScript.female == false)
                {
                    mating     = false;
                    hide       = false;
                    matingUrge = 0;

                    Instantiate(this.gameObject, new Vector3(this.gameObject.transform.position.x + 1,
                                                             this.gameObject.transform.position.y,
                                                             this.gameObject.transform.position.z), Quaternion.Euler(Random.Range(-180f, 180f), Random.Range(-180f, 180f), Random.Range(-180f, 180f)));
                }
            }
        }
    }