Hello Guest

Author Topic: Lerp colors/alpha and javascript  (Read 4058 times)

mammothboy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Lerp colors/alpha and javascript
« on: February 21, 2013, 05:10:30 pm »
Hello.
I can't seem to be able to change through lerp the alpha of the sprites, how can i do it?
Also, i only understand javascript and the scripts os 2dtoolkit come in C#, i already did the "Setup for Javascript" thing, but nothing changed, all scripts are still C#.

Thank you for your time.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lerp colors/alpha and javascript
« Reply #1 on: February 21, 2013, 11:46:21 pm »
Setup for JavaScript lets you access the scripts from JavaScript, it won't change the code for you. C# and JS are surprisingly similar to each other. You should be able to convert the no problem with a tiny bit of understanding.

Code: [Select]
using UnityEngine;
using System.Collections;

public class TutorialSpriteScript : MonoBehaviour {

tk2dSprite sprite;

// Use this for initialization
void Start () {
    sprite = GetComponent<tk2dSprite>();
}

// Update is called once per frame
void Update () {
        if (Input.GetKeyDown(KeyCode.A))
        {
            sprite.color = Color.red;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            sprite.color = Color.white;
        }
    }
}

becomes...

Code: [Select]
#pragma strict


var sprite : tk2dSprite;

function Start() {
sprite = GetComponent(tk2dSprite);
}

function Update() {
if (Input.GetKeyDown(KeyCode.A))
{
sprite.color = Color.red;
}
if (Input.GetKeyDown(KeyCode.S))
{
sprite.color = Color.white;
}
}