【发布时间】:2017-03-23 04:46:06
【问题描述】:
我正在 Unity 中创建一个游戏,其中我必须有一个玩家(一个球)和三个敌人(在本例中是三个旋转的圆柱体)。每当玩家击中敌人时,我需要它死(我已经这样做了)然后打印出 Game over,我不知道该怎么做。我还需要玩家在它死后重生,这是另一个我不知道该怎么做的想法。我还需要创建三个“虚拟洞”,当玩家翻过它们时,它会重生,但不会死亡。我想我可以通过创建扁平圆柱体来模拟孔,但我不知道如何让球重生,而是滚过它们。先感谢您!!请明确回答中的哪一部分。
//My player script
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody rb;
public float threshold;
public Text gameOver;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
//rolls the player according to x and z values
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
}
//my script that makes the enemy rotate and kills the player but after the
player dies it just disappears
public class Rotater : MonoBehaviour {
public Text gameOver;
// Update is called once per frame
void Update ()
{
transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);
}
//kills player
void OnCollisionEnter(Collision Col)
{
if (Col.gameObject.name == "Player")
{
Destroy(Col.gameObject);
gameOver.text = "Game over!";
}
}
//my script that respawns the play if it falls off the maze
public class Respawn : MonoBehaviour
{
// respawns player if it goes below a certain point (falls of edge)
public float threshold;
void FixedUpdate()
{
if (transform.position.y < threshold)
transform.position = new Vector3(-20, 2, -24);
}
}
【问题讨论】: