Beispiel #1
0
    public void SpawnCircle(VirusSpawnMode virusSpawnMode)
    {
        this.transform.parent = GameObject.Find("Balls").transform;

        Rigidbody2D rigidbody = this.gameObject.GetComponent <Rigidbody2D>();

        rigidbody.AddTorque(Random.Range(-maxTorque, maxTorque));
        rigidbody.velocity = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f)) * Random.Range(minSpeed, maxSpeed);

        int randomNumber = Random.Range(0, 4);

        Material objectMaterial = this.gameObject.GetComponent <Renderer>().material;

        switch (virusSpawnMode)
        {
        case VirusSpawnMode.Healthy:
            objectMaterial.color = Color.green;
            break;

        case VirusSpawnMode.Virus:
            objectMaterial.color = Color.red;
            break;

        case VirusSpawnMode.Random:
            IsVirus = (randomNumber == 1) ? true : false;
            objectMaterial.color = (IsVirus) ? Color.red : Color.green;
            break;
        }


        VirusBallManager.AddBall(this);
    }
Beispiel #2
0
    void OnMouseDown()
    {
        Material material = this.gameObject.GetComponent <Renderer>().material;

        if (material.color == Color.red)
        {
            material.color = Color.green;

            VirusBallManager.HealBall();
        }
    }
Beispiel #3
0
    // Start is called before the first frame update
    void Start()
    {
        VirusBallManager.Initialise();

        screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height));

        Debug.Log("Screen width " + Screen.width + " Screen Height " + Screen.height);       // Width in pixels
        Debug.Log("ScreenBounds x " + screenBounds.x + " ScreenBounds y " + screenBounds.y); //

        var cam         = Camera.main;
        var bottomLeft  = cam.ViewportToWorldPoint(new Vector3(0.5f, 0, cam.nearClipPlane));
        var bottomRight = cam.ViewportToWorldPoint(new Vector3(1, 0, cam.nearClipPlane));
        var topRight    = cam.ViewportToWorldPoint(new Vector3(1, 1, cam.nearClipPlane));
        var topLeft     = cam.ViewportToWorldPoint(new Vector3(0.5f, 1, cam.nearClipPlane));

        // Width
        var wallWidth = topRight.x / 50;

        // Add top wall
        GameObject wall = Instantiate(wallPrefab) as GameObject;

        wall.transform.position   = topLeft;
        wall.transform.localScale = new Vector3(topRight.x, wallWidth, wall.transform.localScale.z);

        // Add bottom wall
        wall = Instantiate(wallPrefab) as GameObject;
        wall.transform.position   = bottomLeft;
        wall.transform.localScale = new Vector3(topRight.x, wallWidth, wall.transform.localScale.z);

        // Add left wall
        wall = Instantiate(wallPrefab) as GameObject;
        wall.transform.localScale = new Vector3(wallWidth, topRight.y, wall.transform.localScale.z);
        wall.transform.position   = cam.ViewportToWorldPoint(new Vector3(0, 0.5f, cam.nearClipPlane));

        // Add right wall
        wall = Instantiate(wallPrefab) as GameObject;
        wall.transform.localScale = new Vector3(wallWidth, topRight.y, wall.transform.localScale.z);
        wall.transform.position   = cam.ViewportToWorldPoint(new Vector3(1, 0.5f, cam.nearClipPlane));

        // Spawn first healthy viruas
        GameObject a         = Instantiate(circlePrefab) as GameObject;
        var        virusBall = a.GetComponent <VirusBall>();

        virusBall.SpawnCircle(VirusBall.VirusSpawnMode.Healthy);
        a.transform.position = new Vector2(Random.Range(-screenBounds.x, screenBounds.x), Random.Range(-screenBounds.y, screenBounds.y));


        VirusBallManager.CurrentGameStatus = VirusBallManager.GameStatus.Started;



        StartCoroutine(VirusWave());
    }
Beispiel #4
0
    void OnCollisionEnter2D(Collision2D col)
    {
        Material objectMaterial         = this.gameObject.GetComponent <Renderer>().material;
        Material collidedObjectMaterial = col.gameObject.GetComponent <Renderer>().material;

        if ((objectMaterial.color == Color.green) &&
            (collidedObjectMaterial.color == Color.red))
        {
            objectMaterial.color = Color.red;

            VirusBallManager.InfectBall();
        }
    }