//Change Color
    public void SwitchPlayerColor(ColorUsed newColor)
    {
        SpriteRenderer renderer = PlayerSphere.GetComponent <SpriteRenderer>();

        switch (newColor)
        {
        case ColorUsed.Red:
            renderer.color = Colors[0];
            break;

        case ColorUsed.Yellow:
            renderer.color = Colors[1];
            break;

        case ColorUsed.Green:
            renderer.color = Colors[2];
            break;

        case ColorUsed.Blue:
            renderer.color = Colors[3];
            break;

        case ColorUsed.Purple:
            renderer.color = Colors[4];
            break;

        default:
            renderer.color = Colors[0];
            break;
        }
    }
Exemple #2
0
    public ColorUsed[] AllowedColor;          // to choic the color from allowed colors
    void OnTriggerEnter2D(Collider2D other)   //To know when the ball reaches the circles
    {
        if (other.gameObject.tag == "Player") //player الحاجه الى بتحرك بيها التاج بتاعها اسمه
        {
            ManagerReferences refs = GameObject.Find("Manager").GetComponent <ManagerReferences>();
            int       index        = Random.Range(0, AllowedColor.Length - 1);
            ColorUsed newColor     = AllowedColor[index];

            refs.SwitchPlayerColor(newColor);
            this.gameObject.SetActive(false); //Make coin Hidden
            Destroy(this);                    //Make coin Destroy the script
        }
    }