C# 统一游戏麻烦
我正在创建一个统一的游戏,我必须有一个玩家(一个球)和三个敌人(在这个例子中是三个旋转的圆柱体)。每当玩家击中敌人时,我需要它死去(我已经这样做了),然后打印游戏结束,我不知道怎么做。我还需要玩家死后重生,这是我不知道该怎么做的另一个想法。我还需要创建三个“虚拟洞”,当玩家翻滚过它们时,它会重生,但不会死亡。我想我可以通过创建平面圆柱体来模拟洞,但我不知道如何使球重生,而是在它们上面滚动。提前谢谢你!!请明确你的答案中哪一部分是什么C# 统一游戏麻烦,c#,unity3d,C#,Unity3d,我正在创建一个统一的游戏,我必须有一个玩家(一个球)和三个敌人(在这个例子中是三个旋转的圆柱体)。每当玩家击中敌人时,我需要它死去(我已经这样做了),然后打印游戏结束,我不知道怎么做。我还需要玩家死后重生,这是我不知道该怎么做的另一个想法。我还需要创建三个“虚拟洞”,当玩家翻滚过它们时,它会重生,但不会死亡。我想我可以通过创建平面圆柱体来模拟洞,但我不知道如何使球重生,而是在它们上面滚动。提前谢谢你!!请明确你的答案中哪一部分是什么 //My player script public class
//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);
}
}
//我的播放器脚本
公共类玩家控制器:单行为
{
公众浮标速度;
私人刚体;
公众浮动阈值;
公共文本游戏;
//用于初始化
void Start()
{
rb=GetComponent();
}
//每帧调用一次更新
//根据x和z值滚动播放器
void FixedUpdate()
{
float moveHorizontal=Input.GetAxis(“水平”);
float moveVertical=Input.GetAxis(“垂直”);
Vector3移动=新Vector3(水平移动,0.0f,垂直移动);
rb.AddForce(移动*速度);
}
}
//我的脚本,使敌人旋转并杀死玩家,但在
玩家死了,它就消失了
公共类轮换者:单一行为{
公共文本游戏;
//每帧调用一次更新
无效更新()
{
变换.旋转(新矢量3(15,30,45)*时间增量);
}
//杀死玩家
无效碰撞中心(碰撞柱)
{
如果(Col.gameObject.name==“玩家”)
{
销毁(游戏对象列);
gameOver.text=“游戏结束!”;
}
}
//我的剧本,如果它从迷宫里掉下来,它就会重生
公共阶层重生:单一行为
{
//如果玩家低于某一点(边缘下降),则使其重生
公众浮动阈值;
void FixedUpdate()
{
if(变换位置y<阈值)
transform.position=新向量3(-20,2,-24);
}
}
您需要创建一个UI在游戏上绘制文本。您可以了解它
当用户界面就位后,您可以使用激活/停用相关部件
要杀死并复活玩家,我建议你不要摧毁它并重新实例化它。相反,你可以简单地停用它,然后再次使用SetActive(bool)
在新位置重新激活它
对于这些洞,您可以使用碰撞器创建其他对象,并使用OnCollisionCenter
,就像您已经做的那样,但可以更改玩家的位置。请参阅滚球教程: