团结游戏的麻烦

时间:2017-03-22 18:59:49

标签: c# unity3d

我在Unity中创造了一个游戏,我必须有一个玩家(一个球)和三个敌人(在这种情况下是三个旋转的圆柱体)。每当玩家击中敌人时,我都需要它死掉(我已经做过),然后将游戏打印出来,我不知道该怎么办。我还需要玩家在死后重生,这是另一种想法,我不知道该怎么做。我还需要创建三个"虚拟洞"当玩家翻过它们时,它会重生,但不会死亡。我想我可以通过制作扁平圆柱体来模拟洞穴,但我不知道如何让球重新生成但是翻过来。先感谢您!!请清楚你的答案中哪一部分做了什么。

//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);
}
}

1 个答案:

答案 0 :(得分:0)

您需要创建一个用于在游戏中绘制文字的UI。您可以了解here

当您拥有用户界面时,您只需使用SetActive(bool)激活/停用相关部分。

要杀死并重生玩家,我建议你不要破坏它并重新实例化它。相反,您只需停用它,然后再次使用SetActive(bool)在新位置重新激活它。

对于这些洞,您可以使用对撞机创建其他对象并使用OnCollisionEnter,但更改玩家的位置。

相关问题