[Simple Guide] Tap to Change Eye Color
Earlier today, I was trying to find a way on how to tap the screen to change the eye color, and I searched very long for it until I found a thread, that guided me through it. I am here to help others, so I will spread the content that I found here so it is easier for all to find it. I'm sure I am not the only person wondering this, so I created this as a simple guide on how to add 'tap to change eye color'.
Credit goes to Brandon / Apoc on figuring this out on this thread. I am posting to help you all, and I hope you guys can find this quickly, without struggle! :)
____________________________________________________________________
//@input Component.EyeColorVisual eye
// This will return or be used to set the eye color:
script.eye.mainPass.baseColor
It uses a vec4 for the color as its RGBA format, the values are 0 to 1 instead of a 0-255 though. To randomize you need to generate a random decimal 0-1 for each of R, G, and B. and A if you want to change the opacity/alpha.
Your script for choosing a random color will look something like this:
//@input Component.EyeColorVisual eye
var red = Math.random()*(1-0)+0;
var green = Math.random()*(1-0)+0;
var blue = Math.random()*(1-0)+0;
// I set the alpha to 40% because I felt it looks the best, feel free to change 0.4 to anything 0-1
script.eye.mainPass.baseColor = new vec4(red, green, blue, 0.4);
then you put that in any event you want, in this case you wanted it in the tap event (I actually use touch start since it detects taps much faster)
//@input Component.EyeColorVisual eye
var event = script.createEvent("TouchStartEvent");
event.bind(function(eventData) {
var red = Math.random()*(1-0)+0;
var green = Math.random()*(1-0)+0;
var blue = Math.random()*(1-0)+0;
// I set the alpha to 40% because I felt it looks the best, feel free to change 0.4 to anything 0-1
script.eye.mainPass.baseColor = new vec4(red, green, blue, 0.4);
});
Credit goes to Brandon / Apoc for finding this :)
Cheers,
Darius
Thanks alot!