正如标题所说,我如何在Unity中用C#做到这一点?我自己尝试了一些东西,但是随着我尝试过的东西,我的播放器总是出现在屏幕上。所以我想知道应该怎么做。 http://pastebin.com/q60xgvZM - PlayerScript.cs http://pastebin.com/AuHzYhtH - MoveScript.cs(我不知道这个是否对你们有用) 这是我的GameButtons.cs,我试图让按钮进入(不介意评论。我喜欢复制和粘贴):
using UnityEngine;
public class GameButtons : MonoBehaviour
{
void OnGUI()
{
const int buttonWidth = 60;
const int buttonHeight = 60;
// Draw a button to start the game
if (
GUI.Button(
// Center in X, 2/3 of the height in Y
new Rect(
Screen.width / 5 - (buttonWidth / 2),
(3 * Screen.height / 4) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"UP"
)
)
{
// On Click, load the first level.
// "Stage1" is the name of the first scene we created.
speed.x += Vector2.up * 10;
}
if (
GUI.Button(
// Center in X, 2/3 of the height in Y
new Rect(
Screen.width / 5 - (buttonWidth / 2),
(13 * Screen.height / 14) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"DOWN"
)
)
{
// On Click, load the first level.
// "Stage1" is the name of the first scene we created.
speed.y += Vector2.down * 10;
}
if (
GUI.Button(
// Center in X, 2/3 of the height in Y
new Rect(
Screen.width / 8 - (buttonWidth / 2),
(5 * Screen.height / 6) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"LEFT"
)
)
{
speed.x += Vector2.left * 10;
}
if (
GUI.Button(
// Center in X, 2/3 of the height in Y
new Rect(
Screen.width / 4 - (buttonWidth / 2) + 24,
(5 * Screen.height / 6) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"RIGHT"
)
)
{
// On Click, load the first level.
// "Stage1" is the name of the first scene we created.
speed.y += Vector2.right * 10;
}
if (
GUI.Button(
// Center in X, 2/3 of the height in Y
new Rect(
(Screen.width / 1) - (buttonWidth * 2) - 20,
(5 * Screen.height / 6) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"FIRE"
)
)
{
// On Click, load the first level.
// "Stage1" is the name of the first scene we created.
Application.LoadLevel("ShootEmUp");
}
}
}
答案 0 :(得分:1)
你的场景规模是多少?速度是否有可能让玩家在屏幕外移动?
顺便提一句,您的“向上”输入正在修改x而不是y。