Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Waitforseconds causing erratice flickering between active/not active objects

$
0
0
Hi I've written a script which on a Right-Click an Animatior activates and a caption appears. This toggles, so right-click again and the Animation reverses and the caption disappears. The Animation takes about 2 seconds to compelte and I want to caption to appear after the Animation has finished, but then dissapear immediately on the second click. I have the script below using a Coroutine to Waitforsecond (2) on SetActive(true). The activation works perfectly, there is a 2 second delay after the animation starts and the caption appears on time. But on the second right click, for SetActive(false), it just flickers erratically on and off for 2 seconds before dissapearing! Do you know what's causing this flickering? I'm a compelte beginner to javascript so any help is really appreciated. Thankyou :) #pragma strict internal var animator : Animator; private var anno : GameObject; var clickCounter: int; var click : float; function Start () { clickCounter = 0; animator = GetComponent(Animator); anno = GameObject.Find("Caption1"); } function Update () { Counter(); Activation(); } function FixedUpdate () { animator.SetFloat("Activate", click); } function Counter () { if(Input.GetMouseButtonDown(1)) { if(clickCounter == 0) { clickCounter = 1; } else { clickCounter = 0; } } } function Activation () { if(clickCounter%2==0) { click = 0.0; anno.SetActive(false); } else { click = 0.2; yield WaitForSeconds (2); anno.SetActive(true); } }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>