Esempio n. 1
0
    /// <summary>
    /// Randomly changes the color of the material that this instance has.
    /// </summary>
    public void AssignRandomColor()
    {
        int       randomIndex = Random.Range(0, (int)ToonColor.COUNT);
        ToonColor randomColor = (ToonColor)randomIndex;

        SetColor(randomColor);
    }
Esempio n. 2
0
    /// <summary>
    /// Changes the color of the material that this instance has.
    /// </summary>
    /// <param name="color">Color.</param>
    public void SetColor(ToonColor color)
    {
        Texture2D colorTexture = null;

        CurrentColor = color;

        switch (color)
        {
        case ToonColor.Blue:
            colorTexture = blueColorTexture;
            break;

        case ToonColor.Green:
            colorTexture = greenColorTexture;
            break;

        case ToonColor.Red:
            colorTexture = redColorTexture;
            break;

        case ToonColor.Yellow:
            colorTexture = yellowColorTexture;
            break;
        }


        Renderer ourRenderer  = GetComponent <MeshRenderer>();
        Material tempMaterial = new Material(ourRenderer.sharedMaterial);

        tempMaterial.SetTexture("_MainTex", colorTexture);
        ourRenderer.sharedMaterial = tempMaterial;
    }