Unity3D Input.GetKeyDown无效

时间:2017-11-28 20:04:09

标签: c# unity3d

我遇到一个问题,当我尝试继续我的文字冒险游戏时,Input.GetKeyDown无效。

一旦我到达游戏中关于从地上拿起针的故事,我提示用户按下三个键中的一个。

我试图更改播放器按下的键并且没有解决问题。

我还添加了一个Debug.Log语句,以确保按下该键。

public class ComicTextController : MonoBehaviour {

//publically exposing the gameText varible
public Text gameText;
//setting the Enum for states
private enum States { comic1, comic2, comic3, comic4, comic5, tryagain };        //Place new states here in the {} brackets
//States from enum varible
private States myState;

// Use this for initialization
void Start () {
    myState = States.comic1;
}

// Update is called once per frame
void Update () {
    if (myState == States.comic1)
    {
        state_comic1();
    } else if(myState == States.comic2)
    {
        state_comic2();
    } else if (myState == States.tryagain)
    {
        state_tryagain();
    }
    else if (myState == States.comic3)
    {
        state_comic3();
    } else if(myState == States.comic4)
    {
        state_comic4();
    }
}

void state_comic1()
{
    gameText.text = "Rocket: Make sure to look both ways before crossing the street!I love going to Phoenix Comics." +
                    "They’re always so nice to me there.Did you know they do game events nearly every night of the… uh oh!" +
                    "Is that a needle on the ground? What do we do?\n\n"+
                    "Player: Pick it up. (Press the P key to pick it up)\n\n" +
                    "Player: Ignore it, go inside the store, and forget about it. (Press I to ignore)\n\n" +
                    "Player: Notice where it is, go inside the store, and tell an adult. (Press the S key to go into the Store)";

    if (Input.GetKeyDown(KeyCode.P))
    {
        state_comic2();
        Debug.Log ("Pressed the P Key");

    } else if (Input.GetKeyDown(KeyCode.I))
    {
        state_comic3();

    } else if (Input.GetKeyDown(KeyCode.S))
    {
        state_comic4();

    }

}

void state_comic2()
{
    gameText.text = "Rocket:  No way! Sharp needles (sharps) are hazardous. They may be bright and colorful, but they’re not for children." +
                    "Maybe we should tell an adult?\n\n" +
                    "Press the T Key to try again";
    if (Input.GetKeyDown(KeyCode.T))
    {
        state_tryagain();
    }
}

void state_tryagain()
{
    gameText.text = "Rocket: Make sure to look both ways before crossing the street!I love going to Phoenix Comics." +
                    "They’re always so nice to me there.Did you know they do game events nearly every night of the… uh oh!" +
                    "Is that a needle on the ground? What do we do?\n\n" +
                    "Player: Ignore it, go inside the store, and forget about it. (Press I to ignore)\n\n" +
                    "Player: Notice where it is, go inside the store, and tell an adult. (Press the S key to go into the Store)";
    if (Input.GetKeyDown(KeyCode.I))
    {
        state_comic3();
    } else if (Input.GetKeyDown(KeyCode.S))
    {
        state_comic4();
    }
}

void state_comic3()
{
    gameText.text = "Rocket: Although they seem like trash because they’re abandoned on the ground," +
                    "sharp needles (sharps) are hazardous, especially where there are lots of people walking around." +
                    "Maybe we should tell an adult?\n\n" +
                    "Press the T key to try again";
    if (Input.GetKeyDown(KeyCode.T))
    {
        state_tryagain();
    }
}

void state_comic4()
{
    gameText.text = "Rocket:  They were so grateful we let them know about the sharp needles (sharps) out in front." +
                    "Now they can carefully clean them up or let the city authorities know. Good work!\n\n" +
                    "Press the Right Arrow key to advance";
    if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        SceneManager.LoadScene("UrbanJungleStreet");
    }


 }

}

问题出在state_comic1()方法中。

0 个答案:

没有答案