Hi,
I've made a pretty simple button script, it's not perfect so I'm looking for feedback on ways to improve or make it function slightly better. Just whack it on a cube in Unity with box collier with the trigger bool on and you have a super simple button.
using UnityEngine;
using System.Collections;
using Leap;
public class OnTrigger : MonoBehaviour {
// Use this for initialization
public GameObject squeeze;
public AudioClip[] audioClip;
public Color colorStart = Color.green;
public Color colorEnd = Color.red;
public float dur = 3.0f;
public Renderer rend;
public float scale = 0f;
float countDown = 10.0f;
void OnTriggerEnter ()
{
squeeze.transform.localScale += new Vector3 (0,0.01f,0);
FadeColor ();
PlaySound (0);
}
void OnTriggerExit ()
{
rend.material.color = colorStart;
squeeze.transform.localScale -= new Vector3 (0,0.01f,0);
}
void PlaySound (int clip)
{
AudioSource audio = GetComponent<AudioSource> ();
audio.clip = audioClip[clip];
audio.Play ();
}
void FadeColor ()
{
float lerp = Mathf.PingPong (Time.time, dur) / dur;
rend.material.color = Color.Lerp (colorStart, colorEnd, lerp);
}
}
The idea was to fade the color with lerp from start to end while your hand is over the button and also animate the scale of the button to give some extra feedback. It's not entirely perfect so any heads up on how to improve this would be more than welcomed.
My aim is to make some super simple assets for people to get going with in Orion as it feels the change has shaken some people. And being a newbee myself I think I find some of the larger scripts harder to deconstruct, so I reckon some simpler style 'taster' scripts and some youtube tuts could be really beneficial to people starting out.