Unity Disregarding Input

I just need help figuring out is something is conflicting.

I walk to the object and it pops up “Press E”, i press E and it brings up the prompt but if i press 1 or 2 it doesn’t do anything else. I have the inputs set to 1 and 2 and everything else works.

import UnityEngine.UI;

var TextDisplay : GameObject;
var TheDistance : float = PlayerCasting.DistanceFromTarget;

var TheDoor : GameObject;
var Price : int;
var trig : int = 0;

function Update () {
    TheDistance = PlayerCasting.DistanceFromTarget;
    if (TheDistance > 12)
    {
        trig = 0;
    }
    if (Input.GetButtonDown("Action")) {
    trig = 1;
        if (TheDistance <= 12) {
            if (Input.GetButtonDown("Yes"))
            {

                if(Rand() == 1)
                {
                    Destroy(gameObject);
                }
                else if (Rand() == 2)
                    {
                        trig = 0;
                    }
            }
            else if (Input.GetButtonDown("No"))
            {
                    trig = 0;
            }
        }
    }
       
}

function OnMouseOver () {
    if (TheDistance <= 12 && trig == 0) {
        TextDisplay.GetComponent.<Text>().text = "Press E";
    }
    else if (TheDistance <= 12 && trig == 1)
    {
        Prompt();
    }
}

function OnMouseExit () {
    TextDisplay.GetComponent.<Text>().text = "";
}

function Rand ()
{
var rand:int = Random.Range(0,3);
return rand;
}
function Prompt ()
{
    TextDisplay.GetComponent.<Text>().text = "Do you wish to Spend $" + Price + " to ask the conch\n Press 1. Yes\n Press 2. No";
}

You have Input.GetButtonDown(“Yes”)/(“No”) inside the if statement for (“Action”). Input.Get*Down functions are only true for the single frame the button is first pressed, so it’ll only trigger if you press both buttons at precisely the same time.

Instead, use the first input (“Action”) to set some variable indicating the player has pressed that button, and then, check that variable; inside THAT if statement, you check for further input.

1 Like