Hello Guest

Author Topic: animatedSprite and color changing  (Read 4874 times)

Eldh

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
animatedSprite and color changing
« on: August 11, 2012, 11:30:47 am »
Hi i'm relatively new to unity and programing so sry if it's a noobish question :)
I'm trying to change randomly the color of an animatedSprite wich is itself instantiate a certain number of time. So i have an array of color and pick up one randomly, but the abimatedSprite appear to be all transparent, without color in the viewport when i it play. But if i choose one color like animatedSprite.color = Color.green it's working.
Code: [Select]
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class spawnEnemy : MonoBehaviour
{

    public tk2dAnimatedSprite enemy;
    public Color[] colorChoices;
    public GameObject road;
    public List<Transform> spawnPoint;
    private tk2dAnimatedSprite target;
    private int n = 0;
    private int p = 0;
    private Vector3 pos = new Vector3();
 

 
    void Start()
    {

            p = Random.Range(0, colorChoices.Length);
            n = Random.Range(0, spawnPoint.Count);
            target = (tk2dAnimatedSprite)Instantiate(enemy, spawnPoint[n].transform.position, enemy.transform.rotation);
            target.color = colorChoices[p];
            target.transform.parent = road.transform;
            pos = road.transform.position;
}}
       

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: animatedSprite and color changing
« Reply #1 on: August 11, 2012, 12:08:15 pm »
What is the alpha value on the colors in the inspector? If alpha is low / zero then the sprite will be transparent.

Eldh

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: animatedSprite and color changing
« Reply #2 on: August 11, 2012, 02:12:01 pm »
oh... sry for that, it was so obvious i didn't think about it. Thx.