2d sprite script error

In my 3d game i have a jumpscare that is a 2d Sprite and i have this script but it wont work! can anyone tune it up for my application or give me some pointers please :slight_smile: i need to make the object show up for 3 seconds 18 seconds into pressing E but not an animation (That was a failed attempt to make it work

var Figure : GameObject;
var Moveup : Animation;

function Start () {
    if (Input.GetKeyDown ("e"))
    yield WaitForSeconds (18.0);
    GameObject.Find("Figure").GetComponent.<Animation>().Play("Moveup");
    yield WaitForSeconds (2.5);
}

But i also have this script attached to the same object

var radioInRange;
var radioActivated;
var radioSound : AudioClip;

public var guiSkin : GUISkin;

private var hasPlayed = false;

function OnTriggerEnter (c : Collider)
{
    radioInRange = true;

}
function OnTriggerExit (c : Collider)
{
    radioInRange = false;

}
function OnGUI ()
{
    if(radioInRange == true)
    {
        GUI.skin = guiSkin;
        GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50), "Turn on radio");
  
    }

}
function Update ()
{
    if (radioInRange == true)
    {
        if (Input.GetKeyDown ("e"))
        {
            if(!hasPlayed)
            {
                AudioSource.PlayClipAtPoint(radioSound, transform.position);
                hasPlayed = true;
          
            }
      
        }
  
    }

}

If you just started to learn programming, you might want to look into C# instead of UnityScript (aka pseudo JavaScript). Unity Technologies is going to remove UnityScript at some point, see here.

So, start only works once. It triggers the very first frame of your game, so it’s not going to detect your input, this is why it doesn’t work.

Input usually is detected in Update. That is problem 1. The second issue is your if statement has no brackets, so right now, you are simply telling it if e is pushed, wait 18 secs. Make sure you group lines together with curly brackets if you plan to have them work with the if.

The other thing is, 18 secs is a long time and you probably don’t want to trigger this more than once, so I would have a bool to make sure it can’t be triggered multiple times.

So what I would do is move your start code to Update. Have it check for input key and a bool is false. Then within the if, have it set your bool to true and call another method that will trigger your waits and such.

And as @Peter77 suggested, consider switching to c#.

When you go ahead and move to C# , you should consider moving to the newer UI system, as well (dropping OnGUI) :slight_smile: