我正在为5.3版本的机器人制作游戏,当scree被轻击时,玩家向上移动并且必须继续点击,但是当游戏开始时玩家跌倒并且不在游戏区域!我想要做的是在游戏开始时让玩家保持静止,这样当屏幕被点击时游戏就开始了!这是代码..
public class Player : MonoBehaviour {
public string currentColor;
public float jumpForce = 10f;
public Rigidbody2D circle;
public SpriteRenderer sr;
public Color blue;
public Color yellow;
public Color pink;
public Color purple;
public static int score = 0;
public Text scoreText;
public GameObject obsticle;
public GameObject colorChanger;
void Start () {
setRandomColor ();
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown ("Jump") || Input.GetMouseButtonDown (0))
{
circle.velocity = Vector2.up * jumpForce;
}
scoreText.text = score.ToString ();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Scored")
{
score++;
Destroy (collision.gameObject);
Instantiate (obsticle, new Vector2(transform.position.x,transform.position.y + 7f), transform.rotation);
return;
}
if (collision.tag == "ColorChanger")
{
setRandomColor ();
Destroy (collision.gameObject);
Instantiate(colorChanger, new Vector2(transform.position.x,transform.position.y + 7f), transform.rotation);
return;
}
if (collision.tag != currentColor) {
Debug.Log ("You Died");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
score = 0;
}
if (collision.tag == "Floor")
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
void setRandomColor()
{
int rand = Random.Range (0, 4);
switch (rand)
{
case 0:
currentColor = "Blue";
sr.color = blue;
break;
case 1:
currentColor = "Yellow";
sr.color = yellow;
break;
case 2:
currentColor = "Pink";
sr.color = pink;
break;
case 3:
currentColor = "Purple";
sr.color = purple;
break;
}
}
}
答案 0 :(得分:1)
首先制作circle.isKinematic = true;
首次点按即可转到circle.isKinematic = false;