- Home /
Fading between two objects in UnityScript
Hey guys!
I'm trying to fade between two objects in UnityScript. At the moment, it's just two images in separate Canvas Groups but eventually it's going to also be the fog density, colours, meshes appearing, etc so I'm looking for a fairly flexible solution. Trying to do it in UnityScript mostly because I'm new and I'm much more familiar with code than I am with the Unity animation editor. Not a great coder though!
At the moment, it's switching between the two but it's a little glitchy and doesn't work as seamlessly as I hope it would. Not sure if I'm just trying to do something with Canvas Groups that I shouldn't do or whether it's a problem in my code.
Would love your help! Thanks in advance.
Here is the code:
function Update () {
if (Input.GetKeyDown("mouse 1")) {
if (animFinished) {
animFinished = false;
FadeModes();
}
}
}
function FadeModes() {
var t : float;
if (eyesOn) {
for (t = 0.0f; t < 1.0f; t += Time.deltaTime / 2.0f) {
earsCanvas.alpha += t;
eyesCanvas.alpha -= t;
yield;
}
}
else {
for (t = 0.0f; t < 1.0f; t += Time.deltaTime / 2.0f) {
eyesCanvas.alpha += t;
earsCanvas.alpha -= t;
yield;
}
}
animFinished = true;
eyesOn = !eyesOn;
}
Your answer
Follow this Question
Related Questions
Fade-In/Out shadows for a specific object 0 Answers
Solution for animating material to preserve DrawCall batching 0 Answers
Sprite renderer vs image renderer issues on canvas 1 Answer
Alpha not displaying when changed in code, unless changed manually in the inspector 0 Answers
Fade animation in 1 Answer